ios-sdk
ios-sdk copied to clipboard
NowPlayingView demo project with SpotifyiOS.xcframework on iPhone X with iOS 14.4 keeps getting AppRemote disconnects. Project built using Xcode 12.4 on a MacBook Pro M1 / macOS Big Sur 11.2.2
Background info
I cloned this repository and built the NowPlayingView demo project in Xcode 12.4 running on a MacBook Pro M1 with macOS Big Sur 11.2.2.
The commit that I cloned the repo at was the current HEAD of the master branch; commit 711bd15.
Xcode was complaining about the SpotifyiOS.framework, so I configured the project to use the SpotifyiOS.xcframework instead. (Both of which are included in your repository.)
I changed the Xcode project name, Display Name, Bundle Identifier and registered the app on Spotify Developer and modified the project accordingly.
I build the project and ran it on my iPhone X, which is running iOS 14.4.
I am running the latest version of Spotify on my iPhone X; Spotify version 8.6.6.1099 according to the "about" screen in the settings view inside of the Spotify app.
I press play in the demo app, and the first time I do this I authorize it in Spotify and Spotify starts to play music as it should.
I am using a Spotify Free account.
Problem description and reproduction
The NowPlayingView demo app works most of the time but every now and then AppRemote disconnects.
In particular:
-
Seems to be working: When Spotify was not running before, and is launched by pressing the play button in the NowPlayingView demo app, and I keep the screen unlocked and the NowPlayingView demo app in the foreground, the NowPlayingView demo app seems to keep working as it should through multiple songs and ads.
-
Seems to be working: Likewise, if Spotify is launched by the NowPlayingView demo app, and I then switch to Spotify and go to My Library and Shuffle Play a Playlist, and then switch back to the NowPlayingView demo app, then the NowPlayingView demo app seems to keep working as it should through multiple songs and ads.
-
AppRemote disconnect: If Spotify is launched by the NowPlayingView demo app, and I keep the NowPlayingView demo app in the foreground but I do a swipe down gesture to pull down the iOS notifications view and then swipe the notifications view back up again then the NowPlayingView demo app will correctly display the currently playing song but then when the next song or ad starts playing, then in the NowPlayingView demo app AppRemote disconnects. This happens both when I launch the NowPlayingView demo app on the device from Xcode, and when I launch the NowPlayingView demo app from the home screen of the device itself.
-
AppRemote disconnect: If Spotify is already playing music before I start the NowPlayingView demo app on the device from Xcode, then the NowPlayingView demo app will correctly display the currently playing song but then when the next song or ad starts playing, then in the NowPlayingView demo app AppRemote disconnects. This happens when I launch the NowPlayingView demo app on the device from Xcode, but does not seem to happen when I launch the NowPlayingView demo app from the home screen of the device itself.
This is the behavior that I have been able to repeatedly observe in the NowPlayingView demo app so far on my iPhone X running iOS 14.4.
Error details
When the AppRemote disconnect happens, and I am running on the device via Xcode, I get error messages that look like this in the Xcode output window:
2021-03-07 19:33:59.451472+0100 WhatsPlaying[3145:345004] SocketStream read error [0x283fd82c0]: 1 54
2021-03-07 19:33:59.452160+0100 WhatsPlaying[3145:345004] AppRemote: Disconnected with error: Error Domain=com.spotify.app-remote.transport Code=-2000 "Stream error." UserInfo={NSLocalizedDescription=Stream error., NSUnderlyingError=0x2806bcfc0 {Error Domain=NSPOSIXErrorDomain Code=54 "Connection reset by peer" UserInfo={_kCFStreamErrorCodeKey=54, _kCFStreamErrorDomainKey=1}}, NSLocalizedRecoverySuggestion=Reconnect the transport to the Spotify app., NSLocalizedFailureReason=A stream error has occured in the transport.}
didDisconnectWithError
2021-03-07 19:34:33.632458+0100 WhatsPlaying[3145:345004] AppRemote: Disconnecting...
@BalestraPatrick do you guys also see this happen? Also, let me know if you guys want any video recordings to show the problem in action, or if the text in the issue report is enough.
+1 @ctsrc I'm having exactly the same issues! I'm also running Xcode 12 but on an Intel Catalina machine. Also had to use SpotifyiOS.xcframework and while the NowPlayingView app runs, I get very buggy behavior with intermittent disconnects as described above.
Hi @ctsrc, nice find.
This actually seems to be a bug in the NowPlayingView sample app.
The issue is that we're using sceneDidBecomeActive
and sceneWillResignActive
to connect and disconnect App Remote. These functions are called multiple times when you're swiping down notifications. My guess is that this causes a broken connection because connect
will be called just before disconnect
is called a final time. This leaves App Remote in a connected state, even if the app is currently in the background, since the last connection call will receive its callbacks right after the disconnect call is made.
Anyway, it doesn't really make any sense to use sceneDidBecomeActive
and sceneWillResignActive
for handling App Remote connection state, because those functions could be called frequently for minor events like system alert etc.
So, the solution here is probably to use sceneDidEnterBackground(_ :)
and sceneWillEnterForeground(_ :)
instead.
This bug was likely introduced when migrating from using UIAppDelegate to UISceneDelegate in the sample project and is likely to affect iOS 13 too.
Hopefully we're able to publish an updated sample project soon. In the mean time let us know if this didn't solve the problem.
@danielgronlund -- thanks for the information update! I'm also wondering, whoudl we always be using the xcframework from now on? I haven't been able to get the .framework to work correctly in Xcode 12.
I'm really looking forward to the sample player updates as the documentation for the SDK is..sparse. I'm currently looking at the sample code as the best way to understand how the SDK works and best practices for using it in the meantime.
@megeek There isn't any reason to avoid using the XCFramework if your setup doesn't prevent you from using it. The .framework can still be useful in some situations, like if you're dependent on the legacy build system.
The .framework should work in Xcode 12 but there seems to have been an issue with the latest build since it's missing the arm64 slice. If you need to use the .framework, please use the official release build for now.
@danielgronlund Thanks again for the information. I can confirm that the missing arm64 slice was what was causing me issues using the .framework...I'll stay on the XCFramework for now!
@ctsrc After a deeper investigation we found that this issue was infact due to a bug in the connection handling of the Spotify app.
I was making an assumption that the issue was purely due to a race condition in my previous comment, but that turned out to be incorrect. sceneDidBecomeActive
and sceneWillResignActive
should still be used to handle connections if you want resume connections after being interrupted by an incoming call or such. So, you can disregard my previous comment.
The issue is resolved and should be included in an upcoming update of the Spotify app. Thanks for reporting.
Thank you @danielgronlund
@danielgronlund when do you plan to release the update?
@danielgronlund when do you plan to release the update?
Agreed: would be nice to know if the fix is taking longer than expected.
- This still appears to be reproducible on Spotify iOS v 8.6.16 and v 8.6.18 using the sample app and in another project on my end.
@danielgronlund any news here?