登录FitBit登录页面后如何重定向回我的iOS应用? [英] How to redirect back to my iOS app after logging in on FitBit login page?
问题描述
我正在用Swift开发一个非常基本的iOS应用.只是读取心率数据.我正在使用SFSafariViewController.众所周知,我首先需要在dev.fitbit.com上注册我的应用程序.注册表格要求输入回叫URL.
I am developing a very basic iOS app with Swift. Just to read the heart rate data. I am using SFSafariViewController. As known, I first need to register my app on dev.fitbit.com. The registration form requires a callback URL to be entered.
成功登录后,FitBit始终将我重定向回输入的回调URL.成功登录后,我应该怎么做/编码/配置才能将用户重定向回我的iOS应用程序?
After logging in successfully, FitBit always redirects me back to that entered callback URL. What should I do/code/configure to be able to redirect user back to my iOS app after logging in successfully?
推荐答案
您需要做的是将application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool
函数添加到AppDelegate中,然后为您的应用程序创建一个URL方案作为标识符.要创建url方案,请转到您的应用程序目标>信息> URL类型(在底部).然后只需在AppDelegate中添加以下内容即可:
What you need to do is to add the application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool
function to your AppDelegate and then create an url scheme for your application as an identifier. To create an url scheme go to your application target > Info > URL Types (at the bottom). Then just add the following in your AppDelegate:
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
DispatchQueue.main.async {
// Conctrol so that we´re coming from the right application
if (url.scheme == "The url scheme that you created"){
// Navigate to the viewController you want
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let controller = storyboard.instantiateViewController(withIdentifier: "WebView") as! WebViewController
self.window?.rootViewController!.present(controller, animated: true, completion: { () -> Void in
})
}
}
return true
}
这篇关于登录FitBit登录页面后如何重定向回我的iOS应用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!