我一直在使用 Twitter.sharedInstance().session()?.userName
在 iOS(在 Swift 中)的标签中显示用户的推特地址。现在我注意到我们收到以下弃用警告:
-[Twitter session] will soon be deprecated. It is recommended that users use -[TWTRSessionStore session] or -[TWTRSessionStore sessionForUserID:] if they are managing multiple users
我切换到推荐方式,并期望找到一个 .userName
属性,但找不到。
人们打算如何换出 Twitter.sharedInstance().session()?.userName
向前发展?
最佳答案
好吧,我也遇到了这个问题,似乎所有较新的更改(公认的记录非常少)都是为了更好地控制同时存在的多个用户 session 而设计的。我深入研究了 TWTRSessionStore
他们在警告中提到的类,我发现虽然 TWTRSessionStore 的具体实现没有 -session
属性,它遵守以下协议(protocol) <TWTRUserSessionStore, TWTRGuestSessionStore, TWTRSessionRefreshingStore>
和 TWTRUserSessionStore
确实有 -session
属性(property)。
所以,总而言之,这就是我注销的方式:
NSString *userID = [[[[Twitter sharedInstance] sessionStore] session] userID];
if(userID){
[[[Twitter sharedInstance] sessionStore] logOutUserID:userID];
}
很明显,我是在 Objective-C 中做的,但 Swift 版本非常相似。
关于ios - 在 iOS Swift 上弃用后 Twitter.sharedInstance().session()?.userName 的替代方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32668059/