Spotify 会话续订问题

Spotify Session Renewal Issue

我正在尝试在我的 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。

好的,解决了。我正在存储我的会话,但忘记将它重新分配给 sessionManager。这样我的会话总是为零,并且在请求续订时没有刷新令牌导致它不是 return 新的访问令牌。

通过重新分配会话解决了这个问题!