ios-sdk
ios-sdk copied to clipboard
appRemoteDidEstablishConnection not called
After calling appRemote.connect() and returning to the app from the Spotify login window appRemoteDidEstablishConnection is never executed but instead it always calls didFailConnectionAttemptWithError.
Here's the code I have.....
@IBAction func connectToSpotify(_ sender: Any) {
let requestedScopes: SPTScope = [.appRemoteControl]
self.sessionManager.initiateSession(with: requestedScopes, options: .default)
}
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
self.sessionManager.application(app, open: url, options: options)
return true
}
func sessionManager(manager: SPTSessionManager, didInitiate session: SPTSession) {
print("success", session)
self.appRemote.connectionParameters.accessToken = session.accessToken
self.appRemote.connect()
}
func sessionManager(manager: SPTSessionManager, didFailWith error: Error) {
print("fail", error)
}
func sessionManager(manager: SPTSessionManager, didRenew session: SPTSession) {
print("renewed", session)
}
func appRemoteDidEstablishConnection(_ appRemote: SPTAppRemote) {
print("connected")
self.appRemote.playerAPI?.delegate = self
self.appRemote.playerAPI?.subscribe(toPlayerState: { (result, error) in
if let error = error {
debugPrint(error.localizedDescription)
}
})
}
func appRemote(_ appRemote: SPTAppRemote, didDisconnectWithError error: Error?) {
print("disconnected")
}
func appRemote(_ appRemote: SPTAppRemote, didFailConnectionAttemptWithError error: Error?) {
print("failed")
}
func playerStateDidChange(_ playerState: SPTAppRemotePlayerState) {
print("player state changed")
}
And this is the error I get after trying to connect....
AppRemote: Failed connection attempt with error: Error Domain=com.spotify.app-remote.transport Code=-2000 "Stream error." UserInfo={NSLocalizedDescription=Stream error., NSUnderlyingError=0x600001377360 {Error Domain=NSPOSIXErrorDomain Code=61 "Connection refused" UserInfo={_kCFStreamErrorCodeKey=61, _kCFStreamErrorDomainKey=1}}, NSLocalizedRecoverySuggestion=Reconnect the transport to the Spotify app., NSLocalizedFailureReason=A stream error has occured in the transport.}
I get this when the spotify app is not playing a song. To connect, I have always to make sure spotify is playing something. It's annoying for my use case, but did not find other way around it - see this issue:
[https://github.com/spotify/ios-sdk/issues/53]
I get the same as @earln8 but even when the spotify app is playing a song. I get this even with the "NowPlayingView" demo project.
Here the log output:
2018-12-18 10:33:34.430804+0100 NowPlayingView[15275:4893515] AppRemote: Connecting...
2018-12-18 10:33:34.454383+0100 NowPlayingView[15275:4893589] [] nw_socket_handle_socket_event [C1.1:1] Socket SO_ERROR [61: Connection refused]
2018-12-18 10:33:34.455788+0100 NowPlayingView[15275:4893589] [] nw_socket_handle_socket_event [C1.2:1] Socket SO_ERROR [61: Connection refused]
2018-12-18 10:33:34.455981+0100 NowPlayingView[15275:4893591] [] nw_connection_get_connected_socket [C1] Client called nw_connection_get_connected_socket on unconnected nw_connection
2018-12-18 10:33:34.456467+0100 NowPlayingView[15275:4893591] TCP Conn 0x2831e9e00 Failed : error 0:61 [61]
2018-12-18 10:33:34.456898+0100 NowPlayingView[15275:4893515] AppRemote: Failed connection attempt with error: Error Domain=com.spotify.app-remote.transport Code=-2000 "Stream error." UserInfo={NSLocalizedDescription=Stream error., NSUnderlyingError=0x280abe940 {Error Domain=NSPOSIXErrorDomain Code=61 "Connection refused" UserInfo={_kCFStreamErrorCodeKey=61, _kCFStreamErrorDomainKey=1}}, NSLocalizedRecoverySuggestion=Reconnect the transport to the Spotify app., NSLocalizedFailureReason=A stream error has occured in the transport.}
didFailConnectionAttemptWithError
2018-12-18 10:34:34.971814+0100 NowPlayingView[15275:4893515] AppRemote: Disconnecting...
The solution proposed by @jackfreeman in https://github.com/spotify/ios-sdk/issues/35 does not work in my case (see comment above).
Made sure that configuration.playURI = "" is done when constructing the SPTConfiguration object and still the same error.
Running on an iPhone 6s with iOS 12.0 (16A366) model MKQT2ZD/A with 128 GB Capacity and 6.58 GB Available
I am getting the same error regardless if the Spotify app is playing or not playing a song. The workaround for me is to restart the Spotify app.
@kkarayannis is there any plan to tackle this? I am facing the issue both with my app and the sample NowPlayingView app. The Spotify app seems to enter a state that is unrecoverable and no matter what I do I cannot connect to it. It seems to enter that state after a long time of inactivity.
The only viable solution for now is to prompt my user to restart the Spotify app which is far from ideal.
The Spotify app seems to enter a state that is unrecoverable and no matter what I do I cannot connect to it. It seems to enter that state after a long time of inactivity.
I have seen this behavior myself. I'd like to fix this asap but it's really hard to reproduce as, like you said, only happens after long periods of inactivity and only happens sometimes.
@kkarayannis if I get the Spotify app in that state would it help to message you? Happens quite often for me. Perhaps you can debug remotely.
I'm having the same exact problem as @fotiDim mentioned above ^ (getting this same exact error after the Spotify app has been "inactive" for multiple hours). Has anyone found a solution yet?
I'm facing the same issue, Please update answer if any of you have. Thanks
I hope this issue is not forgotten. This is a report I got from a user:
If Spotify is playing a song, and I open up the app, the player will show nothing is playing. Force quitting your app does not help. If I force quit Spotify and then start up your app and start a song, then the player works.
Any updates on this? If it helps I confirmed that it happens with both AppRemote authentication and SPTSession authentication. It actually does not happen after long inactivity. Usage pattern does not seem to be relevant. In fact it seems to be totally random. Sometimes it happens for 3 days in a row. Sometimes I need to wait for a week before it happens. In either case it can happen after consequent runs of the app so if you are a bit persistent it will happen.
@kkarayannis there has been too much silence on this. It is happening for me daily. Can you please put some priority on this?