Reputation: 9149
I'm having trouble with Spotify beta 9. All the tutorials seem phased out regarding saving a SPTSession and updating(refreshing) with the RefreshTokenURL. This is how I'm getting the AuthViewController....
let spotifyAuthenticationViewController = SPTAuthViewController.authenticationViewController()
spotifyAuthenticationViewController.delegate = self
spotifyAuthenticationViewController.modalPresentationStyle = UIModalPresentationStyle.OverCurrentContext
spotifyAuthenticationViewController.definesPresentationContext = true
presentViewController(spotifyAuthenticationViewController, animated: true, completion: nil)
Now I need to create a session, save, and periodically refresh. I would like to save in CoreData. Please help if you've done this before or have any good tips
Upvotes: 3
Views: 511
Reputation: 236
at time of writing, beta 25 does this automagically for you if you set auth.sessionUserDefaultKey
when you config your session.
You can then check for a valid session
(auth.session != nil && auth.session.isValid)
Upvotes: 0
Reputation: 951
You have to store it in 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];
}
Upvotes: 5