Search code examples
facebookfacebook-graph-apiios4facebook-ios-sdk

Facebook Graph API: Resume Session on iPhone


I have been playing with the Facebook Graph API since yesterday and it is pretty good, however, I have been searching around the web for some method of resuming a session. That is, once a user has gone through the authentication (of allowing an app to use their data), logging in automatically when they open the app (or even providing a login button).

I have found plenty of posts on FBSession and using [session resume]. The problem is, these have been removed. What is the new method of resuming a users session and logging in?


Solution

  • After succesfully logging in your Facebook object will have the token values in

    [Facebook accessToken]
    [Facebook expirationDate]
    

    Save these values (I recommend NSUserDefaults).

    The next time the app starts, restore them with

    Facebook.accessToken = savedAccessToken;
    Facebook.expirationDate= savedExpirationDate;
    

    Then is [Facebook isAuthorized] to verify if the token is still valid, if it is, you can consider yourself logged in.