Check Facebook Connect Session on IOS

2 Solutions Collect From Internet About “Check Facebook Connect Session on IOS”

After a successful login, you want to save the access token and expiration date, like this:

[[NSUserDefaults standardUserDefaults] setObject:_facebook.accessToken forKey:@"AccessToken"];
[[NSUserDefaults standardUserDefaults] setObject:_facebook.expirationDate forKey:@"ExpirationDate"];
[[NSUserDefaults standardUserDefaults] synchronize];

Then, when you load the app, you want to check if there is a saved token, like this:

_facebook = [[Facebook alloc] initWithAppId:@"[app_id]"];
_facebook.accessToken    = [[NSUserDefaults standardUserDefaults] stringForKey:@"AccessToken"];
_facebook.expirationDate = (NSDate *) [[NSUserDefaults standardUserDefaults] objectForKey:@"ExpirationDate"];
if (![_facebook isSessionValid]) {
    [_facebook authorize:_permissions delegate:self];
else {
    [_facebook requestWithGraphPath:@"me" andDelegate:self];

Hope this helps!

I’m pretty sure it should automatically check if the user is logged in, wether through safari or the Facebook iPhone app. If the user is not logged in, then it will prompt using one of the applications above (default is safari if FB app is not installed, thats why the simulator opens FB in safari).