Check Facebook Connectivity on iOS

In the new Facebook library, the FBSession object has disappeared. How can I check if the user really has a valid session on his device when he launches the application without prompting for safari or uiwebview?

The [facebook isSessionValid] method works with acccessToken, but the accessToken is set when the application returns from safari (or the built-in uiwebview).

Can I verify a session with cookies?

+5
source share
2 answers

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

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

, , , , :

_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];
}

, !

+12

, , , iPhone Facebook. , ( , FB , FB ).

0

All Articles