0

我已经实现了 Facebook 登录,它工作正常。但我对这个屏幕有问题:

在此处输入图像描述

这是由 Facebook 框架直接提供的,所以我不能直接在其上附加操作。该视图用于将我的 Facebook 应用程序与我的 Facebook 帐户相关联。所以问题是:我如何检测用户是否按下取消按钮?我试图打印我的 Facebook 会话状态

- (void)sessionStateChanged:(FBSession *)session
                      state:(FBSessionState) state
                      error:(NSError *)error
{
    NSLog(@"stato %u",state);
    
    switch (state) {
        case FBSessionStateOpen:
            
            break;
        case FBSessionStateClosed:
            break;
        case FBSessionStateCreated:
            break;
        case FBSessionStateCreatedOpening:
            break;
        case FBSessionStateOpenTokenExtended:
            break;
        case FBSessionStateCreatedTokenLoaded:
            break;
        case FBSessionStateClosedLoginFailed:
            // Once the user has logged in, we want them to
            // be looking at the root view.
            
            [FBSession.activeSession closeAndClearTokenInformation];
            break;
        default:
            break;
    }
    if (error) {
        UIAlertView *alertView = [[UIAlertView alloc]
                                  initWithTitle:@"Error"
                                  message:error.localizedDescription
                                  delegate:nil
                                  cancelButtonTitle:@"OK"
                                  otherButtonTitles:nil];
        [alertView show];
    }
}

但它总是返回相同的状态,独立于按下的按钮。

谢谢

4

2 回答 2

1

我已经通过将这行代码添加到 AppDelegate 来解决:

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
    return [FBSession.activeSession handleOpenURL:url]; ;
}

并通过以下方式检查连接状态:

if (!FBSession.activeSession.isOpen) {
}
于 2013-09-30T18:35:11.870 回答
0

总是返回什么状态?这表明还有其他设置不正确?

您应该能够将类似的内容添加到您的 viewWillAppear/viewDidAppear 中。

// See if the app has a valid token for the current state.
if (FBSession.activeSession.state == FBSessionStateCreatedTokenLoaded) {
    // To-do, show logged in view
} else {
    // No, display the login page.
    [self showLoginView];
}
于 2013-09-30T15:29:26.087 回答