问题
I just overhauled my codebase to use the new facebook-ios-sdk 3.0 (from the previous version, 2.x or whatnot).
Everything worked great, until I realized I hadn't accounted for users who had already granted the app permission/logged in with the previous implementation of the SDK. So I tried checking to see if the accessToken was saved in NSUserDefaults, and if so, make a call to open a session:
if ([[NSUserDefaults standardUserDefaults] objectForKey:@"FBAccessTokenKey"] &&
[[NSUserDefaults standardUserDefaults] objectForKey:@"FBExpirationDateKey"]) {
[FBSession openActiveSessionWithPermissions:permissions
allowLoginUI:allowLoginUI
completionHandler:^(FBSession *session,
FBSessionState status,
NSError *error) {
// deal with state change
}
My assumption was that the user wouldn't have to fast app switch for SSO, since they already had. However, that is indeed what happens.
I'd rather not have every existing user need to re-login when upgrading.
Has anyone successfully upgraded without having to re-login?
Thanks
回答1:
I have upgraded an app with the facebook SDK 3.0 and it worked just fine. The Facebook SDK handles the token itself, but you can still access the accessToken.
You can reach it any time like so:
NSString *accessToken = [FBSession activeSession].accessToken;
This will return the accessToken or a nil if no token is set. You can even define a token caching ruleset on the session. Enjoy.
回答2:
The answer is in another post by my colleague. We were able to upgrade users from SDK pre 3.0 to 3.1 without needing users to re-login. It involves the use of the FBSessionManualTokenCachingStrategy:
how to avoid logging users out when migrating from iOS Facebook 2.x -> 3.x
来源:https://stackoverflow.com/questions/12380410/migrating-existing-access-tokens-to-facebook-ios-sdk-3-0