Facebook SDK本机登录错误

时间:2014-10-14 00:25:43

标签: ios facebook

注意:我正在关注Native Facebook Login stopped working after SDK update to 3.14的本机登录建议。

错误如下:

  

2014-10-13 20:03:27.378注册[1916:407643]错误   Domain = com.facebook.sdk Code = 9"尚未授予访问权限   脸书账号。验证设备设置。"的UserInfo = 0x1753c630   {NSLocalizedDescription =未授予Facebook访问权限   帐户。验证设备设置。,NSLocalizedFailureReason = Access具有   没有被授予Facebook帐户。验证设备设置。}

这是下面的代码:

// RegistrationManager.m

- (void)setupFacebook
{
    FBSessionStateHandler completionHandler = ^(FBSession *session, FBSessionState status, NSError *error) {
        [self sessionStateChanged:session state:status error:error];
    };

    if ([FBSession activeSession].state == FBSessionStateCreatedTokenLoaded)
    {
        // we have a cached token, so open the session
        [[FBSession activeSession] openWithBehavior:FBSessionLoginBehaviorUseSystemAccountIfPresent
                                  completionHandler:completionHandler];
    }
    else
    {
        [self clearAllUserInformation];

        // create a new facebook session
        FBSession *fbSession = [[FBSession alloc] initWithPermissions:@[@"public_profile"]];
        [FBSession setActiveSession:fbSession];
        [fbSession openWithBehavior:FBSessionLoginBehaviorUseSystemAccountIfPresent completionHandler:completionHandler];
    }
}

- (void)clearAllUserInformation
{
    [FBSession.activeSession closeAndClearTokenInformation];
    [FBSession renewSystemCredentials:^(ACAccountCredentialRenewResult result, NSError *error) {
        NSLog(@"%@", error);
    }];
    [FBSession setActiveSession:nil];
}

// RegistrationViewController.m

- (IBAction)loginButtonPressed:(id)sender
{
    // If the session state is any of the two "open" states when the button is clicked
    if (FBSession.activeSession.state == FBSessionStateOpen
        || FBSession.activeSession.state == FBSessionStateOpenTokenExtended)
    {
        // Close the session and remove the access token from the cache
        // The session state handler (in the app delegate) will be called automatically
        [FBSession.activeSession closeAndClearTokenInformation];

        // If the session state is not any of the two "open" states when the button is clicked
    } else
    {
        FBSessionStateHandler completionHandler = ^(FBSession *session, FBSessionState status, NSError *error) {
            [registrationManager sessionStateChanged:session state:status error:error];
        };

        // create a new facebook session
        FBSession *fbSession = [[FBSession alloc] initWithPermissions:@[@"public_profile"]];
        [FBSession setActiveSession:fbSession];
        [fbSession openWithBehavior:FBSessionLoginBehaviorUseSystemAccountIfPresent completionHandler:completionHandler];
    }
}

当我点击按钮时,它只是说

  

2014-10-13 20:03:29.560注册[1916:407643]会议结束   2014-10-13 20:03:29.561注册[1916:407643]用户注销   2014-10-13 20:03:29.573注册[1916:407643]用户注销。

1 个答案:

答案 0 :(得分:1)

这意味着用户曾在要求许可的弹出窗口中选择“不允许”。如果他将自己的Facebook帐户链接到“设置”中,从现在开始,每次他尝试登录时都会显示此错误。它不会回退到Safari或任何东西,只显示此错误。用户需要进入设置 - > Facebook并将应用程序的滑块设置为ON。