2
Spotify iOS SDK全部位於objective-c中,截至今天,它看起來像使用SDK的任何請求都需要令牌。當我嘗試搜索一首歌,我得到這個錯誤:在Spotify iOS SDK中設置身份驗證令牌
["error": { message = "No token provided"; status = 401; }]
這裏是我的appDelegate代碼:
var auth = SPTAuth()
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
//Neccessary Spotify stuff
auth.redirectURL = URL(string: "my_redirect_url")
auth.sessionUserDefaultsKey = "current session"
FIRApp.configure()
window = UIWindow(frame: UIScreen.main.bounds)
window?.makeKeyAndVisible()
window?.rootViewController = CustomTabBarController()
return true
}
// 1
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
// 2- check if app can handle redirect URL
if auth.canHandle(auth.redirectURL) {
// 3 - handle callback in closure
auth.handleAuthCallback(withTriggeredAuthURL: url, callback: { (error, session) in
// 4- handle error
if error != nil {
print("error!")
}
// 5- Add session to User Defaults
let userDefaults = UserDefaults.standard
let sessionData = NSKeyedArchiver.archivedData(withRootObject: session as Any)
userDefaults.set(sessionData, forKey: "SpotifySession")
userDefaults.synchronize()
// 6 - Tell notification center login is successful
NotificationCenter.default.post(name: Notification.Name(rawValue: "loginSuccessfull"), object: nil)
})
return true
}
return false
}
如何設置在斯威夫特令牌?