0

我是 facebook SDK 和 iOS 开发人员的新手,当用户登录 facebook 时,我的应用程序出现问题,当我使用相同的帐户 fb 登录时,我的应用程序总是显示此登录对话框: 在此处输入图像描述

我希望我的应用程序仅在第一次登录 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

4

1 回答 1

0

我想这会对你有所帮助,看看:

Facebook 开发者专区

于 2013-04-06T10:16:03.487 回答