2

I'm new to iOS development. I'm trying to integrate Fitbit in my app. I followed get authorization from Fitbit using Oauth in iOS and FitBit documentation. I used following code

- (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"]];

} 

It launches the Safari app and I fill my credentials and tap Allow means an error is showing in Safari like "Safari cannot open the page because address is invalid". I'm new to iOS development and don't know how to proceed further. Can some one help me to solve this. thanks in advance.

Community
  • 1
  • 1
e.k
  • 1,333
  • 1
  • 17
  • 36

1 Answers1

1

Adding following function in AppDelegate solved my problem, hope it works for you too.

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
}
Himani C.
  • 84
  • 6