1

我创建了一个 Facebook 应用程序。我测试了它,sandbox mode它很好。

现在我想让其他人在手机上测试这个应用程序,所以我关闭sandbox mode了,我发现iPhone-5用户无法登录,但它在android手机上仍然可以正常工作

这是错误日志 -

会话创建错误:错误域 = com.facebook.sdk 代码 = 2“操作无法完成。(com.facebook.sdk 错误 2。)”用户信息 = 0x16561ad0

我检查了我的bundle idand app id,它没有出错

4

2 回答 2

7

这对我有用:

转到 iPhone 的设置应用程序。打开您的 Facebook 设置 向下滚动到您的应用,并确保您的应用允许 Facebook 交互。这可能发生在任何设备上,因此在您的应用程序中,您必须确保正确处理此错误。我认为您向用户反馈了使用 Facebook 登录失败的原因,并要求用户检查其设备上的 Facebook 设置。

- (void)facebookSessionStateChanged:(FBSession *)session state:(FBSessionState)state error:(NSError *)error{       switch (state) {
    case FBSessionStateOpen:
        // handle successful login here
    case FBSessionStateClosed:
    case FBSessionStateClosedLoginFailed:
        [FBSession.activeSession closeAndClearTokenInformation];

        // handle error here, for example by showing an alert to the user
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Could not login with Facebook"
                                                        message:@"Facebook login failed. Please check your Facebook settings on your phone."
                                                       delegate:nil
                                              cancelButtonTitle:@"OK"
                                              otherButtonTitles:nil];
        [alert show];

        break;
    default:
        break;
}
于 2013-09-03T04:33:51.747 回答
1

我使用以下方式及其为我工作:

-(void)openFacebookAuthentication
{
    NSArray *permission = [NSArray arrayWithObjects:kFBEmailPermission,kFBUserPhotosPermission,kFBUserPublicPermission,kFBUserLikePermission, nil];

    FBSession *session = [[FBSession alloc] initWithPermissions:permission];
    [FBSession setActiveSession: [[FBSession alloc] initWithPermissions:permission]];
    [[FBSession activeSession] openWithBehavior:FBSessionLoginBehaviorForcingWebView completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
        switch (status) {
            case FBSessionStateOpen:
                [self likeFaceBook];
                break;
            case FBSessionStateClosedLoginFailed: {
                // prefer to keep decls near to their use
                // unpack the error code and reason in order to compute cancel bool
                NSString *errorCode = [[error userInfo] objectForKey:FBErrorLoginFailedOriginalErrorCode];
                NSString *errorReason = [[error userInfo] objectForKey:FBErrorLoginFailedReason];
                BOOL userDidCancel = !errorCode && (!errorReason || [errorReason isEqualToString:FBErrorLoginFailedReasonInlineCancelledValue]);
                if(error.code == 2) {
                    UIAlertView *errorMessage = [[UIAlertView alloc] initWithTitle:kFBAlertTitle
                                                                           message:kFBAuthenticationErrorMessage
                                                                          delegate:nil
                                                                 cancelButtonTitle:kOk
                                                                 otherButtonTitles:nil];
                    [errorMessage performSelectorOnMainThread:@selector(show) withObject:nil waitUntilDone:YES];
                    errorMessage = nil;
                }
            }
                break;
                // presently extension, log-out and invalidation are being implemented in the Facebook class
            default:
                break; // so we do nothing in response to those state transitions
        }
    }];
    permission = nil;
}
于 2013-09-03T04:43:19.563 回答