spotify / ios-sdk

Spotify SDK for iOS
https://developer.spotify.com/documentation/ios/
661 stars 188 forks source link

Spotify authorizes correctly using `SPTSessionManager` but never connects to `SPTAppRemote` #428

Closed xmollv closed 4 months ago

xmollv commented 4 months ago

I'm implementing the auth flow using SPTSessionManager. I have the auth in theory working, but the SPTAppRemote never ends up connecting.

Here's the flow (and where it breaks without any error nor delegate callback):

Start the auth flow:

sessionManager.initiateSession(with: [.appRemoteControl, .userReadCurrentlyPlaying], campaign: nil)

Then my app is opened by the Spotify iOS app, and I call this method:

self.sessionManager.application(application, open: url, options: options)

Then this delegate method is called, for which I return true to let the iOS SDK handle the auth code exchange:

SPTSessionManagerDelegate.sessionManager(manager:shouldRequestAccessTokenWith:)

Then, when my server made the exchange of the code for an access token, I get this delegate callback:

SPTSessionManagerDelegate.sessionManager(manager:didInitiate:)

The SPTSession I get back on that method seems correct since it includes the accessToken, refreshToken and expirationDate. Inside that method I do the following:

appRemote.connectionParameters.accessToken = session.accessToken
appRemote.connect()

And that's where it ends. I see a log on the console saying AppRemote: Connecting..., but that's about it. I never get any calls to SPTAppRemoteDelegate nor SPTAppRemotePlayerStateDelegate. Also, SPTSessionManagerDelegate never seems to call the error method either.

This is my setup code (the same provided in the sample app):

lazy var configuration: SPTConfiguration = {
    let configuration = SPTConfiguration(clientID: clientID, redirectURL: URL(string: "dumps-spotify://")!)
    configuration.playURI = ""
    configuration.tokenSwapURL = tokenSwapURL
    configuration.tokenRefreshURL = tokenRefreshURL
    return configuration
}()
lazy var sessionManager: SPTSessionManager = {
    let manager = SPTSessionManager(configuration: configuration, delegate: self)
    return manager
}()
lazy var appRemote: SPTAppRemote = {
    let appRemote = SPTAppRemote(configuration: configuration, logLevel: .debug)
    appRemote.delegate = self
    return appRemote
}()

The only difference is that I inject to the class that handles all the Spotify related code the clientID, tokenSwapURL and tokenRefreshURL. I'm using 2.1.1 as the SDK version and the Spotify app is 8.9.50.491.

PS: I also tried running the sample app included on the SDK and it doesn't even authorize. Is something really broken somewhere?

xmollv commented 4 months ago

Without changing anything ~24h later this started to work...