I’m using Xcode 4.3.1
I use the below code to get the Facebook access token.
In Appdelegate:
facebook=[[Facebook alloc]initWithAppId:appid andDelegate:first];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([defaults objectForKey:@"FBAccessTokenKey"]
&& [defaults objectForKey:@"FBExpirationDateKey"])
{
facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
accessToken=facebook.accessToken;
date=facebook.expirationDate;
}
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
return [ self.facebook handleOpenURL:url];
}
Facebook SSO (login)
In viewController:
-(IBAction)LoginClick:(id)sender
{
accesstoken=xapp.accessToken;
date=xapp.date;
[self fbDidExtendToken:xapp.accessToken expiresAt:xapp.date]; //For extending tokens
NSLog(@"accesstoken:%@",accesstoken);
if (![xapp.facebook isSessionValid])
{
[xapp.facebook authorize:permissions];
}
else
{
[xapp.facebook authorize: nil];
}
}
Here I can’t able to handle the sessions properly.My requirement is for the first time user must login and he should authorize the app.Once he done the app should not ask for authorization.Bt now its asking authorization for each and ever time I’m running the app.How can I solve this…..
Do u save the token to user defaults after login ?