Reputation: 10412
I am integrating facebook login in my application. I jsut want the user to be able to login and I get his birthday and Location.
I got the latest Facebook SDK and successfully added it to my application. I also created a new application on facebook and added the key provided to my application.
I have created a button "Login with facebook" and done the following
When the user clicks the button
// handler for button click
- (IBAction)facebookLoginTouched:(id)sender {
[self openSessionWithAllowLoginUI:YES];
}
This method will show the user the facebook login page in order to get his permission
-(BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI {
NSArray *permissions = [[NSArray alloc] initWithObjects:
@"user_location",
@"user_birthday",
nil];
return [FBSession openActiveSessionWithReadPermissions:permissions
allowLoginUI:allowLoginUI
completionHandler:^(FBSession *session,
FBSessionState state,
NSError *error) {
[self HandleLogin];
}];
}
Then if login and permission successful
- (void)HandleLogin {
if (FBSession.activeSession.isOpen) {
//THIS IS NEVER REACHED
[FBRequestConnection
startForMeWithCompletionHandler:^(FBRequestConnection *connection,
id<FBGraphUser> user,
NSError *error) {
//DO SOMETHING WITH THE USER INFO
}];
}
}
My problem:
When I click on the button the facebook page comes in correctly and I enter my username/password. It logged me correctly and I gave permission for the application to access my information. When I finish, I return to the app successfully.
However when the code reaches FBSession.activeSession.isOpen
it returns false.
Why is the session still closed after I correctly logged in and gave permission?
Any help is greatly appreciated.
Thanks
Upvotes: 0
Views: 601
Reputation: 5523
You may be missing code to process the return from the Facebook app. Add the following in your app delegate implementation file:
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
// attempt to extract a token from the url
return [FBSession.activeSession handleOpenURL:url];
}
Upvotes: 2