Search code examples
iosobjective-cxcodefacebookfacebook-ios-sdk

openActiveSessionWithReadPermissions is not calling back when allowLoginUI is "NO"


im updating to lastest sdk facebook (3.10) and i having a problem in the login. When i pass allowLoginUI = YES it logins nicely and the callback block is called. but when i pass allowLoginUI = NO the callback isnt called... i dont know why. I want to pass allowLoginUI = NO when the user already has a session. Here is the code.

- (void)openFBSession:(NSNumber*)active{
    BOOL boolValue = [active boolValue];
    NSArray *permissions = [[NSArray alloc] initWithObjects:@"basic_info, email", nil];
    [FBSession openActiveSessionWithReadPermissions:permissions
                                       allowLoginUI:boolValue
                                  completionHandler:
     ^(FBSession *session,
       FBSessionState state, NSError *error) {
         if (error) {
             // Handle errors
             [self handleAuthError:error];
         } else {
             // No error
             [self sessionStateChanged:session state:state error:error];
         }
     }];
}

Here when i call the function. (The enableScreen is a function that shows the facebookLogin button)

if (FBSession.activeSession.state == FBSessionStateCreated) {
            // Yes, so just open the session (this won't display any UX).
            [self.window.rootViewController performSelector:@selector(enableScreen)];
        } else {
            if (FBSession.activeSession.state == FBSessionStateCreatedTokenLoaded){
                [self openFBSession:[NSNumber numberWithBool:NO]];
            }else{
                [self.window.rootViewController performSelector:@selector(enableScreen)];
            }

        }

Thanks!


Solution

  • The real thing after searching and digging its that if you call openActiveSessionWithReadPermissions with allowLoginUI = NO only will work if you have a token loaded. If not you should call with allowLoginUI = YES