I'm implementing Facebook login in my app using FBSDKLoginManager
. Facebook docs seem to imply that this saves the token for subsequent app launches so that the user doesn't have to log in each time:
The FBSDKLoginManager sets this token for you and when it sets currentAccessToken it also automatically writes it to a keychain cache.
I've been trying to retrieve this token from said cache when the app launches, or display my app's Facebook login screen if it can't be found:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[FBSDKProfile enableUpdatesOnAccessTokenChange:YES];
if ([FBSDKAccessToken currentAccessToken]) {
// user is logged in, continue to app's main screen
} else {
// show login screen
}
//...
}
This shows the login screen every single time. Facebook documentation doesn't explain how this very simple use case should be handled. Am I missing something?
You need to call "[[FBSDKApplicationDelegate sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions]" BEFORE trying to get cached token.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[FBSDKApplicationDelegate sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions];
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With