Andrew Winter
Andrew Winter

Reputation: 1146

iPhone FBConnect always switches to Safari or Facebook app for auth

Is it normal behavior for FBConnect to always switch to the Facebook Application or Safari, even once the user has giving permission once?

Right now my application will create a Facebook object and call authorize, then the iPhone will flip to the Facebook Application to get user permission and once the user has logged and/or giving the okay then it returns to my Application calling - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url I pass the URL to the Facebook object and they can share on their Facebook page. I understand that this is how it is supposed to work the first time... but this happens every time the user chooses to share, even if the application has not closed.

Am I perhaps missing a step to have Facebook Connect store the cookie in my application?

Upvotes: 3

Views: 906

Answers (1)

Henrik P. Hessel
Henrik P. Hessel

Reputation: 36627

You have to save the access token after the user authorized your app

 [[NSUserDefaults standardUserDefaults] setObject:self.facebook.accessToken forKey:@"AccessToken"];
 [[NSUserDefaults standardUserDefaults] setObject:self.facebook.expirationDate forKey:@"ExpirationDate"];

and set it when your app starts.

// Facebook Init
facebook = [[Facebook alloc] init];
facebook.accessToken = [[NSUserDefaults standardUserDefaults] objectForKey:@"AccessToken"];
facebook.expirationDate = [[NSUserDefaults standardUserDefaults] objectForKey:@"ExpirationDate"];

Calling [facebook isSessionValid] will check if the users session is still valid

- (BOOL)isSessionValid {
  return (self.accessToken != nil && self.expirationDate != nil
           && NSOrderedDescending == [self.expirationDate compare:[NSDate date]]);

}

Upvotes: 8

Related Questions