我实施了一个完美的Facebook登录按钮。然而,在用户成功登录到Facebook并返回到应用程序之后, [FBSDKAccessToken currentAccessToken] 返回 NO 。我添加了一个观察者,看看我想要的代码是否在返回到应用程序后运行:
I implemented a Facebook login button which works perfectly fine. However, after user successfully logs in into Facebook and goes back to the app, [FBSDKAccessToken currentAccessToken] returns NO. I added an observer to see if the code I want is running after returning back to the app:
-(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"); } }之后退回登录后该应用程序正在调用 checkLogIn 方法,但 [FBSDKAccessToken currentAccessToken] 仍返回 NO 。 但是,当我按下iPhone上的主页按钮后,它会更改为YES,然后返回到应用程序。
And after Log In when I return to the app the checkLogIn method is being called but [FBSDKAccessToken currentAccessToken] still returns NO. However, it changes to YES after I press home button on iPhone and go back to the app.
如何立即更新,所以我可以向用户显示另一个视图控制器?
How can it be updated immediately, so I can show user another view controller?
更新: 我找到了在回到应用程序后执行正确的代码的方式。关键是使用 FBSDKAccessTokenDidChangeNotification 是通知中心。所以最终的结果将是这样的:
UPDATE: I found out the way to execute proper code after getting back to the app. The key is to use FBSDKAccessTokenDidChangeNotification is Notification Center. So final result will be like this:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(checkLogIn) name: FBSDKAccessTokenDidChangeNotification object:nil];该方式令牌将被更新,它将工作。
That way token will be updated and it will work.
推荐答案请检查您的appDelegate类并实现FB SDK所需的所有方法。我附加的屏幕截图相同。
Please check your appDelegate class and implement all the required methods of FB SDK. I am attaching a screenshot for the same.
更多推荐
FBSDKAccessToken currentAccessToken在登录后没有被更新
发布评论