gpt4 book ai didi

swift - Spotify 续订 session fatal error : unexpectedly found nil while unwrapping an Optional value

转载 作者:行者123 更新时间:2023-11-30 13:51:02 25 4
gpt4 key购买 nike

正在尝试从 Spotify 续订 session ,以便我可以检索新的访问权限并刷新 token 。从第一行打印开始,我收到 fatal error 。

@IBAction func renewSession(sender: AnyObject) {

let auth = SPTAuth.defaultInstance()
auth.tokenRefreshURL = NSURL(string: tokenRefresh)
auth.tokenSwapURL = NSURL(string: tokenSwap)
auth.session = self.spotifySession
auth.sessionUserDefaultsKey = sessionKey

if (auth.session != nil) {

SPTAuth.defaultInstance().renewSession(SPTAuth.defaultInstance().session, callback: {(error, session) -> Void in

if error != nil {

print("The renewed Spotify session is", session)
print("The renewed canonical user name in the session is", session.canonicalUsername)
print("The renewed access Spotify token in session is - %@", auth.session.accessToken)
print("The renewed encrypted refresh Spotify token in session is - %@", auth.session.encryptedRefreshToken)
print("The renewed expiration date of the Spotify access token is - %@", auth.session.expirationDate)

} else {

print ("The problem with the renewal session is", error)

}

})

}

最佳答案

您应该检查if session != nil,而不是if error != nil。存在一些错误,但您的代码正在将控制转移到不正确的流程。

关于swift - Spotify 续订 session fatal error : unexpectedly found nil while unwrapping an Optional value,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34258478/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com