FBSDKAccessToken currentAccessTokenlogin后没有被更新

我实现了一个完美的Facebookloginbutton。 但是,用户成功login到Facebook并返回到应用程序后, [FBSDKAccessToken currentAccessToken]返回NO 。 我添加了一个观察者,看看我想要的代码在返回到应用程序后是否正在运行:

 -(void)viewDidLoad { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(checkLogIn)name :UIApplicationWillEnterForegroundNotification object:nil]; } -(void)checkLogIn { NSLog(@"IN CHECK LOG IN"); if ([FBSDKAccessToken currentAccessToken]) { NSLog(@"Access Token Activated"); } } 

login后,当我返回到应用程序的checkLogIn方法被调用,但[FBSDKAccessToken currentAccessToken]仍然返回NO 。 但是,当我按下iPhone上的主页button后,它会更改为是,并返回到应用程序。

它怎么能立即更新,所以我可以显示用户另一个视图控制器?

更新:我find了回到应用程序后执行正确的代码的方式。 关键是使用FBSDKAccessTokenDidChangeNotification是通知中心。 所以最后的结果会是这样的:

  [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(checkLogIn) name: FBSDKAccessTokenDidChangeNotification object:nil]; 

这种方式令牌将被更新,它将工作。

请检查你的appDelegate类,并实现所有FB SDK所需的方法。 我附上一个相同的截图。

在这里输入图像说明