Monday, 26 August 2013

Facebook iOS SDK sometimes returns null for email

Facebook iOS SDK sometimes returns null for email

I'm trying to get the users name, facebook id and their email by logging
in through my app. The following is in my app delegate:
- (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI
:(FBSessionStateHandler)handler{
NSArray *permissions = [NSArray arrayWithObjects:@"basic_info",
@"email", nil];
return [FBSession openActiveSessionWithReadPermissions:permissions
allowLoginUI:allowLoginUI completionHandler:handler];
}
and my completionHandler code and all is here:
void (^fbCompletionHandler)(FBSession *session, FBSessionState state,
NSError *error) = ^(FBSession *session, FBSessionState state, NSError
*error) {
switch (state) {
case FBSessionStateOpen:
break;
case FBSessionStateClosed:
case FBSessionStateClosedLoginFailed:
[FBSession.activeSession closeAndClearTokenInformation];
break;
default:
break;
}
if (error && [FBErrorUtility shouldNotifyUserForError:error]) {
NSLog(@"%@", error.localizedDescription);
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:@"Oops" message:[FBErrorUtility
userMessageForError:error] delegate:nil cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
}
if (session.isOpen) {
[[FBRequest requestForMe]
startWithCompletionHandler:^(FBRequestConnection *connection,
NSDictionary<FBGraphUser> *user, NSError *error) {
if (!error) {
[self performLoginOperation:user];
}
}];
}
};
and I'm accessing the users email like so: [user objectForKey:@"email"].
Most of the time it works, but every now and then I get a nil value. I'm
not sure why since I set it so in the permissions? Is there any other
reason for this?

No comments:

Post a Comment