I'm trying to integrate Facebook to my app, I've implemented the SSO feature, however I ran into a bit of a snag, once I quit the app I am unable to restore the user's session. I store the token and expiry date as shown:
-(void)fbDidLogin {
NSString *tokenString = [[self facebook] accessToken];
NSDate * expirationDate = [[self facebook] expirationDate];
[[NSUserDefaults standardUserDefaults] setValue: tokenString forKey:@"FacebookToken"];
[[NSUserDefaults standardUserDefaults] setObject: expirationDate forKey:@"FacebookExpirationDate"];
[[NSUserDefaults standardUserDefaults] synchronize];
NSLog(@"Login");
}
this is the delegate method called upon successful login.
and resume the session:
NSString *tokenString = [[NSUserDefaults standardUserDefaults] stringForKey:@"FacebookToken"];
NSDate *expDate = [[NSUserDefaults standardUserDefaults] objectForKey:@"FacebookExpirationDate"];
if (tokenString != nil && expDate != nil)
{
[[facebookFetcher facebook]setAccessToken:tokenString];
[[facebookFetcher facebook] setExpirationDate:expDate];
}
if ([[facebookFetcher facebook] isSessionValid])
{
NSLog(@"YES");
}
else
{
NSLog(@"Bummer");
}
I've tried tackling the problem in a number of ways without luck. One thing I've noticed is that the expiry date seems to be a bit weird: 4001-01-01 00:00:00 +0000 Any suggestions? Thanks.
Your answer is at the following link
Does the Facebook iOS SDK require the user to authenticate every time they use the app?
The date 4001-01-01 00:00:00 +0000 is seen when using the extended permission offline_access .
I ran into trouble with this because I was converting the date into "seconds since 1970" like how it's done on the Android Facebook SDK. If you convert 4001-01-01 to seconds using NSDate
's timeIntervalSince1970
, you'll get a negative number (-2147483648), so watch out.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.