Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
294 views
in Technique[技术] by (71.8m points)

ios - FBSDKAccessToken currentAccessToken is not being updated after log in

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");

        }
 }

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?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Please check your appDelegate class and implement all the required methods of FB SDK. I am attaching a screenshot for the same.

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...