Search code examples
iosfacebookfacebook-ios-sdk

Call Facebook login and then press home button to get back


I have the following problem, I would like to know if there is something implemented by facebook or if you know a workflow to avoid this issue.

Basically I use facebook SDK to login, the app send me to the browser, and instead of clicking cancel or Accept/OK, I click home button and get back to the app. In that case I don't receive any callback from facebook SDK.

Also, facebook have a delay when you click cancel or ok button, so when you get back to the app you don't know exactly if you are going to receive the callback or not by 2-3 seconds aprox.

My current solution is giving a delay of 3-4 seconds and check if you are already connected or not, and show the buttons again if you are not connected. It's a really bad approach, but I can't find something better for that.


Solution

  • You're supposed to handle this in your AppDelegate's applicationDidBecomeActive method:

    - (void)applicationDidBecomeActive:(UIApplication *)application
    {        
        // Handles activation with regards to returning from iOS 6.0 authorization dialog or from fast app switching
        [FBSession.activeSession handleDidBecomeActive];
    }
    

    Docs here: https://developers.facebook.com/docs/reference/ios/current/class/FBSession/#handleDidBecomeActive

    and

    https://developers.facebook.com/docs/ios/ios-sdk-tutorial/authenticate/