How to stay logged in with iOS Facebook SDK 2.4

I use Facebook to enter the application using FBSDKLoginManager . Facebook docs seem to imply that this saves a token for subsequent application launches, so the user does not need to log in every time:

FBSDKLoginManager sets this token for you, and when it sets currentAccessToken, it also automatically writes it to the cache.

I am trying to extract this token from the specified cache when the application starts, or display the login screen of the Facebook application if it cannot be found:

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [FBSDKProfile enableUpdatesOnAccessTokenChange:YES]; if ([FBSDKAccessToken currentAccessToken]) { // user is logged in, continue to app main screen } else { // show login screen } //... } 

This shows the login screen every time. The Facebook documentation does not explain how to handle this very simple use case. Did I miss something?

+7
ios objective-c facebook facebook-ios-sdk
source share
1 answer

You need to call "[[FBSDKApplicationDelegate sharedInstance] application: application doneFinishLaunchingWithOptions: launchOptions]" BEFORE trying to get the cached token.

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [[FBSDKApplicationDelegate sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions]; 

...

+2
source share

All Articles