Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Migrating existing access tokens to Facebook iOS SDK 3.0

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

like image 840
Sahil Avatar asked Sep 12 '12 02:09

Sahil


2 Answers

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.

like image 103
Nils Munch Avatar answered Nov 10 '22 20:11

Nils Munch


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

like image 33
thien Avatar answered Nov 10 '22 22:11

thien