2013-04-06 77 views
0

我是新来的Facebook SDK和iOS deverlop,我的应用在用户登录Facebook时有问题,当我使用同一个帐户登录时,我的应用始终显示此登录对话框: enter image description here如何禁用Facebook登录对话框

我想我的应用程序只显示该对话框当FB账号登录的第一次,但我不知道怎么办呢,这里是我的代码:

- (void)sessionStateChanged:(FBSession *)session state:(FBSessionState) state error:(NSError *)error { 
switch (state) { 
    case FBSessionStateOpen: 
     if (!error) { 
      mainViewController *mainView = [self.storyboard instantiateViewControllerWithIdentifier:@"mainView"]; 
      [self.navigationController pushViewController:mainView animated:YES]; 
      // We have a valid session 
      NSLog(@"User session found"); 
     } 
     break; 
    case FBSessionStateClosed: 
    case FBSessionStateClosedLoginFailed: 
     [FBSession.activeSession closeAndClearTokenInformation]; 
     break; 
    default: 
     break; 
} 

[[NSNotificationCenter defaultCenter] 
postNotificationName:FBSessionStateChangedNotification 
object:session]; 

if (error) { 
    UIAlertView *alertView = [[UIAlertView alloc] 
           initWithTitle:@"Error" 
           message:error.localizedDescription 
           delegate:nil 
           cancelButtonTitle:@"OK" 
           otherButtonTitles:nil]; 
    [alertView show]; 
} 

}

- (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI { 
NSArray *permissions = [[NSArray alloc] initWithObjects: 
         @"email", 
         @"user_likes", 
         nil]; 

return [FBSession openActiveSessionWithReadPermissions:permissions 
              allowLoginUI:allowLoginUI 
            completionHandler:^(FBSession *session, 
                 FBSessionState state, 
                 NSError *error) { 
             [self sessionStateChanged:session 
                  state:state 
                  error:error]; 
            }]; 

}

- (IBAction)authLogin:(id)sender { 
[self openSessionWithAllowLoginUI:YES]; 

}

我用FB SDK 3.2和iOS模拟器6.1

回答

相关问题