到目前为止,我正在尝试在iOS应用中使用Spotify。用户登录并向我提供所需的范围后,我将存储会话,他们可以使用应用程序中的所有内容。当访问令牌过期60分钟后,问题就会出现。那时我正在检索401,并且正在调用函数来续订我的访问令牌,但是这根本不起作用。
private let sessionManager = AppDelegate().sessionManager
func initiateSpotifySession() {
let requestedScopes: SPTScope = [.playlistModifyPublic, .playlistModifyPrivate, .ugcImageUpload]
sessionManager.initiateSession(with: requestedScopes, options: .default)
}
func renewSpotifySession() {
let session = loadSpotifySession()
if session != nil {
sessionManager.renewSession()
} else {
print("login required")
}
}
initiateSpotifySession
可以完美运行,但是一旦我请求sessionManager.renewSession()
函数,它就无法正常工作。没有出现错误,也没有调用以下委托;
func sessionManager(manager: SPTSessionManager, didRenew session: SPTSession) {
print("running the renewal")
}
我的iOS应用程序控制台记录如下内容;
Task <C4C4A6C0-64D7-49EC-81AF-D6E581CD27AE>.<1> finished with error - code: -999
,就是这样。
刷新令牌可用,我可以打印它。不知何故renewSession不起作用。
我用于刷新和检索的服务器是Spotify在其快速入门指南中提供的第一步单击Heroku。
答案 0 :(得分:0)
好的,解决了。我正在存储会话,但是忘记将其重新分配给sessionManager。这样,我的会话始终为零,并且在请求续订时,没有刷新令牌,导致它不返回新的访问令牌。
通过重新分配会话解决了该问题!