My facebook access token is null despite the fact that the button shows that I\'m logged in. Anyone know why this would be?
From RootViewController.m
I have had an issue where I could not get the Access Token because I am calling it before return [[FBSDKApplicationDelegate sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions];
. I needed to check the access token to check whether the user is logged in or not to decide which should be my root view controller. What I did was I tried to get the access token from the cache manually in application didFinishLaunchingWithOptions by:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
FBSDKProfile *cachedProfile = [FBSDKProfile fetchCachedProfile];
[FBSDKProfile setCurrentProfile:cachedProfile];
FBSDKAccessToken *cachedToken = [[FBSDKSettings accessTokenCache] fetchAccessToken];
NSLog(@"Cached Token: %@", cachedToken.tokenString);
if (cachedToken) {
//User is logged in, do logic here.
}
return [[FBSDKApplicationDelegate sharedInstance] application:application
didFinishLaunchingWithOptions:launchOptions];
}
You can see this method by checking the implementation of - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
in FBSDKApplicationDelegate.m
UPDATE
This does not seem to work anymore. I'm not sure why. But it seems that the fetchCachedProfile
and accessTokenCache
methods have been made internal. I could not access these methods anymore in my code as it gives me an error.