StravaSwift icon indicating copy to clipboard operation
StravaSwift copied to clipboard

authorize callback was not called in SwiftUI app

Open antoniokly opened this issue 5 years ago • 5 comments

Hi there, I have followed all the steps, added URI types, so I am able to open the Strava app, authorise and then redirect back to my app when calling StravaClient.sharedInstance.authorize { (result) in print(result) } however the callback { (result) in print(result) } was not called.

It tried your example app, it worked! What am I still missing? I am writing my app using SwiftUI, that is the only difference I can spot.

antoniokly avatar May 20 '20 13:05 antoniokly

I have 2 questions (because I'm seeing the same thing)

  1. What version of iOS are you targeting
  2. Do you also have the Strava app installed when you're running your test?

joeblau avatar Aug 25 '20 04:08 joeblau

@antoniokly I figured it out!

If you're running a pure SwiftUI app this is what you need to do.

@main
struct MyApplication: App {
  var body: some Scene {
    WindowGroup {
      ContentView()
        .onOpenURL { url in
          // This is where you handle the scene opening a URL
          strava.handleAuthorizationRedirect(url)
        }
    }
  }
}

Once you set this up, you'll see the callback in authorized get called and you'll get your access token.

joeblau avatar Aug 25 '20 14:08 joeblau

hi, do you have a full example in SwiftUI?

MacChico1970 avatar Feb 08 '21 21:02 MacChico1970

Actually, I was able to get this working 😅 we can close it.

joeblau avatar Feb 08 '21 21:02 joeblau

I had to instantiate my client using a regular AppDelegate

joeblau avatar Feb 08 '21 21:02 joeblau