ios - 无法将类型 'SPTSession' (0x110afab98) 的值转换为 'SPTSession' (0x10f17f638)

标签 ios swift spotify

我正在使用 Spotify iOS SDK,我正在使用 NSKeyedUnarchiver 存储 session

但是以下代码会导致错误(为清楚起见省略了一些代码):

sptSession = NSKeyedUnarchiver.unarchiveObjectWithData(sessionData as! NSData)
let auth = SPTAuth.defaultInstance()
auth.session = sptSession as! SPTSession

代码的最后一行抛出错误 Could not cast value of type 'SPTSession' (0x110afab98) to 'SPTSession' (0x10f17f638). 我读到这个错误是因为有两种不同的类型SPTSession,但我不确定为什么或如何解决该问题。

最佳答案

答案似乎与这篇 SO 帖子有关:

Swift only way to prevent NSKeyedUnarchiver.decodeObject crash?

我已将问题添加到 Spotify 的 iOS SDK (https://github.com/spotify/ios-sdk/issues/759) 的 GH 存储库中,并将此临时解决方法作为对该问题的评论发布:

暂时,我找到了一个解决方法 - 我可以在存档 session 之前简单地编写 NSKeyedArchiver.setClassName("SPTSession", for: SPTSession.self),然后编写 NSKeyedUnarchiver.setClass(SPTSession.self, forClassName: "SPTSession") 在取消存档之前。

虽然这修复了崩溃,但我将保留此问题,因为我不确定是否可以在基础库中进行更改以修复此问题

关于ios - 无法将类型 'SPTSession' (0x110afab98) 的值转换为 'SPTSession' (0x10f17f638),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39598976/

相关文章:

ios - UILocalNotification 声音不工作

android - 我们如何以编程方式在 Android Q OS 中实现可搜索的进度条?

通过 Spotify Apps API 创建播放列表文件夹

IOS - Swift - UINavigationController.hidesBarsOnSwipe 错误

ios - 如何将完整数据加载到PFQueryTableViewController中并实现objectDidLoad?

ios - UIButton 不自动调整字体大小

ios - Sprite Kit SKAction 组暂停应用程序

ios - 在 Firebase 中的对象数组中查找键

Swift 4 : NSFilenamesPboardType not available. 用什么代替 registerForDraggedTypes?

api - 如何使用 echonest api 获取特定歌曲的 Spotify ID