我是iOS开发的新手。我试图在我的应用中集成Fitbit。我关注了get authorization from Fitbit using Oauth in iOS和FitBit文档。我使用了以下代码
- (IBAction)fitbitLogin:(id)sender {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://www.fitbit.com/oauth2/authorize?response_type=code&client_id=xyxyxy&redirect_uri=xxxxx&scope=activity%20nutrition%20heartrate%20location%20nutrition%20profile%20settings%20sleep%20social%20weight"]];
}
它启动Safari应用程序,我填写我的凭据并点击允许意味着在Safari中显示错误" Safari无法打开页面,因为地址无效"。我是iOS开发的新手,不知道如何继续前进。有人可以帮我解决这个问题。提前致谢。
答案 0 :(得分:1)
在AppDelegate中添加以下功能解决了我的问题,希望它也对您有用。
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
let notification = Notification(name: Notification.Name(rawValue: "NotificationString"), object: nil, userInfo: [UIApplicationLaunchOptionsKey.url:url])
NotificationCenter.default.post(notification)
return true
}