Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to automatically reconnect app remote after Spotify app resumes playback. #347

Open
jadenbanson opened this issue Jan 31, 2022 · 1 comment

Comments

@jadenbanson
Copy link

My app uses the app remote to subscribe to the players state.

But when iOS terminates the Spotify app in the background after another app plays media, then restarts it after I leave that media, app remote becomes disconnected (via "end of stream").

Right now, my only solution is sending the user a push notification telling them to open my app and press a button to reconnect to app remote, which is bad for UX.

Is there anyway to automatically reconnect app remote when the Spotify app resumes playback?

@jayeshtejwani8055
Copy link

jayeshtejwani8055 commented Sep 7, 2022

func appRemote(_ appRemote: SPTAppRemote, didDisconnectWithError error: Error?) {
        reconnectSpotify()
    }
    
    func reconnectSpotify() {
        DispatchQueue.main.asyncAfter(deadline: .now() + 1.5) {
            if !self.appRemote.isConnected {
                self.appRemote.connectionParameters.accessToken = self.accessToken
                self.appRemote.connect()
                self.appRemote.authorizeAndPlayURI("")
            }
        }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants