ios - 在 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() 重新连接)。他们都没有帮助。有什么办法可以解决这个问题,否则我们必须再次重新授权。任何帮助都感激不尽。谢谢。
解决方案
我试过了:
- (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];
}
}
}
推荐阅读
- oracle - 在没有 JavaScript 的情况下将 Oracle PL/SQL 移植到 Snowflake
- python - 从 Django 中的 for 循环创建新的 for 循环
- windows - REG_BINARY 在 Windows 注册表中可以有多大?
- node.js - 从 mongoose 的数组中按 id 删除对象
- javascript - 在 React 中并排放置每个 div 的 2 个元素
- javascript - 触发后如何取消 setTimeout 操作?
- excel - 有关加快此代码的任何建议?
- vue.js - vue数据中声明的数字不能小于0
- reactjs - 如何创建 redux 操作成功和错误回调以触发反应组件处理程序?
- sql - 使用 SQL 从 1 次通过的表中选择两个计数?