Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check Facebook Connect Session on IOS

With the new Facebook library, FBSession object is disappeared. How can i check if user has a valid session on his device immediately when he start the app without prompt to safari or uiwebview ?

The [facebook isSessionValid] method works on acccessToken but accessToken is set when app come back from safari (or inline uiwebview).

Is it possibleto check session using cookies ?

like image 647
MatterGoal Avatar asked Jan 04 '11 17:01

MatterGoal


1 Answers

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!

like image 125
donkim Avatar answered Oct 14 '22 02:10

donkim