Ios 登录Spotify后,如何创建、保存和传递有效的SPCSession?
我在Spotify beta 9上遇到了问题。所有关于保存SPCSession和使用RefreshTokenURL更新(刷新)的教程似乎都被淘汰了。这就是我获取AuthViewController的方式Ios 登录Spotify后,如何创建、保存和传递有效的SPCSession?,ios,swift,core-data,spotify,spotify-app,Ios,Swift,Core Data,Spotify,Spotify App,我在Spotify beta 9上遇到了问题。所有关于保存SPCSession和使用RefreshTokenURL更新(刷新)的教程似乎都被淘汰了。这就是我获取AuthViewController的方式 let spotifyAuthenticationViewController = SPTAuthViewController.authenticationViewController() spotifyAuthenticationViewController.d
let spotifyAuthenticationViewController = SPTAuthViewController.authenticationViewController()
spotifyAuthenticationViewController.delegate = self
spotifyAuthenticationViewController.modalPresentationStyle = UIModalPresentationStyle.OverCurrentContext
spotifyAuthenticationViewController.definesPresentationContext = true
presentViewController(spotifyAuthenticationViewController, animated: true, completion: nil)
现在我需要创建一个会话,保存并定期刷新。我想保存在CoreData中。如果您以前做过此操作或有任何好的提示,请提供帮助您必须将其存储在NSUserDefaults中:
SPTAuth *auth = [SPTAuth defaultInstance];
id sessionData = [[NSUserDefaults standardUserDefaults] objectForKey:auth.sessionUserDefaultsKey];
SPTSession *sessionUserDefault = [NSKeyedUnarchiver unarchiveObjectWithData:sessionData];
auth.tokenRefreshURL = [NSURL URLWithString:kTokenRefreshServiceURL];
if (![sessionUserDefault isValid] && [auth hasTokenRefreshService]) {
[auth renewSession:sessionUserDefault callback:^(NSError *error, SPTSession *renewedSession) {
if (error != nil)
[[NSNotificationCenter defaultCenter] postNotificationName:@"spotifySessionNotOK" object:renewedSession];
if(renewedSession)
self.session = renewedSession;
}];
}
else {
self.session = sessionUserDefault;
}
[auth setSessionUserDefaultsKey:auth.sessionUserDefaultsKey];
}
在撰写本文时,如果您在配置会话时设置了
auth.sessionUserDefaultKey
,beta 25会自动为您执行此操作
然后可以检查有效的会话
(auth.session!=nil&&auth.session.isValid)