mpclarkson / StravaSwift

A Swift wrapper for the Strava API v3
MIT License
102 stars 45 forks source link

authorize callback was not called in SwiftUI app #28

Open antoniokly opened 4 years ago

antoniokly commented 4 years ago

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.

joeblau commented 4 years ago

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 commented 4 years ago

@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.

MacChico1970 commented 3 years ago

hi, do you have a full example in SwiftUI?

joeblau commented 3 years ago

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

joeblau commented 3 years ago

I had to instantiate my client using a regular AppDelegate