How to avoid user registration when switching from iOS Facebook 2.x & # 8594; 3.x

Updating our iOS Facebook integration from 2.x SDK to 3.x SDK automatically registers users who were previously logged in, since the authentication credentials that we used for manual control are now processed off-screen by the new SDK.

Is there a way to force 3.x SDK authentication using the access token and the expiration date that we previously saved manually as a one-time authentication migration?

Thanks in advance!

+4
source share
2 answers

Finally figured it out. The solution involves using the FBSessionTokenCachingStrategy object that they provide, and in particular the FBSessionManualTokenCachingStrategy :

if (isUserUpgrading) { FBSessionTokenCachingStrategy *strategy = [[[FBSessionManualTokenCachingStrategy alloc] initWithUserDefaultTokenInformationKeyName:nil] autorelease]; strategy.accessToken = [[NSUserDefaults standardUserDefaults] stringForKey:@"FBSessionToken"]; // use your own UserDefaults key strategy.expirationDate = [[NSUserDefaults standardUserDefaults] objectForKey:@"FBSessionExpiration"]; // use your own UserDefaults key FBSession *session = [[[FBSession alloc] initWithAppID:@"MY_APP_ID" // use your own appId permissions:nil urlSchemeSuffix:nil tokenCacheStrategy:strategy] autorelease]; [FBSession setActiveSession:session]; } else { [FBSession openActiveSessionWithReadPermissions:...]; // normal authentication } 
+4
source

For Facebook sdk 3.1.1, I had to create a new class FBSessionManualTokenCachingStrategy, which is a subclass of FBSessionTokenCachingStrategy and defines the fetchTokenInformation method as

  - (NSDictionary*)fetchTokenInformation; { return [NSDictionary dictionaryWithObjectsAndKeys: self.accessToken, FBTokenInformationTokenKey, self.expirationDate, FBTokenInformationExpirationDateKey, nil]; } 
0
source

Source: https://habr.com/ru/post/925183/


All Articles