首页 > 解决方案 > 在 iOS 中断开连接后,Spotify AppRemote 不会重新连接

问题描述

我在我的 iOS 应用程序中使用 Spotify 来列出和播放播放列表。最初,我appRemote使用以下范围连接并获取基本播放列表内容,例如 .appRemote、.playlist、. playlistReadPrivate 等

应用程序工作正常,但如果我接到电话,那么我appRemote的连接将与​​以下日志断开连接:

AppRemote:因错误断开连接:错误域=com.spotify.app-remote.transport Code=-2001“流结束。” UserInfo={NSLocalizedRecoverySuggestion=重新连接到 Spotify 应用程序。, NSLocalizedDescription=流结束。, NSLocalizedFailureReason=其中一个流已经结束。}

我尝试在应用程序 WillResignActive 状态下断开 appRemote,并在前台状态下重新启用(使用 appRemote.connect() 重新连接)。他们都没有帮助。有什么办法可以解决这个问题,否则我们必须再次重新授权。任何帮助都感激不尽。谢谢。

标签: iosspotify

解决方案


我试过了:

- (void)appRemote:(SPTAppRemote *)appRemote didFailConnectionAttemptWithError:(NSError *)error

使用计数器变量处理重新连接尝试并增加延迟

[self performSelector:@selector(connect2Spotify) withObject:self afterDelay:3.0];

不完美...但在大多数情况下都有效..

-(void)connect2Spotify
{
    if (self.appRemote!=nil)
    {
        if (!self.appRemote.connected){
            self.appRemote.connectionParameters.accessToken = self.token;
            [self.appRemote connect];
        }
    }
}

推荐阅读