ios Facebook SDK v4.x access token null despite being logged in via FBSDKLoginButton

前端 未结 6 580
花落未央
花落未央 2021-01-04 12:34

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



        
6条回答
  •  耶瑟儿~
    2021-01-04 13:17

    You could build the logic around waiting for FBSDKAccessTokenDidChangeNotification notification in your ViewController's code.

    In your AppDelegate.m:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        // ...
    
        // add observer BEFORE FBSDKApplicationDelegate's - application:didFinishLaunchingWithOptions: returns
        [[NSNotificationCenter defaultCenter] addObserver:self 
                                                 selector:@selector(fbAccessTokenDidChange:) 
                                                     name:FBSDKAccessTokenDidChangeNotification 
                                                   object:nil];
    
        return [[FBSDKApplicationDelegate sharedInstance] application: application     didFinishLaunchingWithOptions: launchOptions];
    }
    
    - (void)fbAccessTokenDidChange:(NSNotification*)notification
    {
        if ([notification.name isEqualToString:FBSDKAccessTokenDidChangeNotification]) {
            if ([FBSDKAccessToken currentAccessToken]) {
                // token is ready to be used in the app at this point
            }
        }
    }
    

提交回复
热议问题