在我的应用程序中使用facebook登录时,始终返回错误FBErrorCategoryUserCancelled

iSm*_*ita 10 facebook uialertview ios7

在我的应用程序中有三种登录方式.其中一个是用facebook登录.但是,当我点击Facebook按钮时,它会询问我访问权限,当点击OK它然后它会重新发出错误FBErrorCategoryUserCancelled.并且这不会发生在每个设备上,它发生在某些设备上.这是我的代码 -

if ([[FBSession activeSession]isOpen]) {
    /*
     * if the current session has no publish permission we need to reauthorize
     */
    if ([[[FBSession activeSession]permissions]indexOfObject:@"publish_actions"] == NSNotFound) {

        [[FBSession activeSession] requestNewPublishPermissions:[NSArray arrayWithObject:@"publish_actions"] defaultAudience:FBSessionDefaultAudienceFriends
                                              completionHandler:^(FBSession *session,NSError *error){

                                                  [ProgressHUD dismiss];
                                                  self.view.userInteractionEnabled = YES;

                                              }];

    }else{

        [self fetchUserDetails];
    }

}else{
    /*
     * open a new session with publish permission
     */
    [FBSession openActiveSessionWithPublishPermissions:[NSArray arrayWithObject:@"publish_actions"]
                                       defaultAudience:FBSessionDefaultAudienceOnlyMe
                                          allowLoginUI:YES
                                     completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
                                         if (!error && status == FBSessionStateOpen) {

                                             [self fetchUserDetails];

                                         }else{

                                             NSLog(@"error");

                                             if ([FBErrorUtility shouldNotifyUserForError:error]) {
                                                 alertTitle = @"Facebook Error";
                                                 alertMessage = [FBErrorUtility userMessageForError:error];

                                                 // This code will handle session closures that happen outside of the app
                                                 // You can take a look at our error handling guide to know more about it
                                                 // https://developers.facebook.com/docs/ios/errors
                                             } else if ([FBErrorUtility errorCategoryForError:error] == FBErrorCategoryAuthenticationReopenSession) {
                                                 alertTitle = @"Session Error";
                                                 alertMessage = @"Your current session is no longer valid. Please log in again.";

                                                 // If the user has cancelled a login, we will do nothing.
                                                 // You can also choose to show the user a message if cancelling login will result in
                                                 // the user not being able to complete a task they had initiated in your app
                                                 // (like accessing FB-stored information or posting to Facebook)

                                             } else if ([FBErrorUtility errorCategoryForError:error] == FBErrorCategoryUserCancelled) {
                                                 NSLog(@"user cancelled login");

                                                 alertTitle  = @"Facebook Error";
                                                 alertMessage = @"System login cancelled";

                                                 // For simplicity, this sample handles other errors with a generic message
                                                 // You can checkout our error handling guide for more detailed information
                                                 // https://developers.facebook.com/docs/ios/errors
                                             } else {
                                                 alertTitle  = @"Something went wrong";
                                                 alertMessage = @"Please try again later.";
                                                 NSLog(@"Unexpected error:%@", error);
                                             }

                                                 [[[UIAlertView alloc] initWithTitle:alertTitle
                                                                             message:alertMessage
                                                                            delegate:nil
                                                                   cancelButtonTitle:@"OK"
                                                                   otherButtonTitles:nil] show];

                                             [ProgressHUD dismiss];
                                             self.view.userInteractionEnabled = YES;

                                         }
                                     }];
}
Run Code Online (Sandbox Code Playgroud)

任何帮助将不胜感激.谢谢.

pwa*_*ang 0

就我而言,这是因为 facebook 应用程序的沙盒模式仍然处于打开状态,因此对于不是该应用程序的管理员/开发人员/测试人员的任何人都会导致 FBErrorCategoryUserCancelled 。

要关闭 Facebook 上的沙盒模式,请转至 https://developers.facebook.com/apps/YOUR_FACEBOOK_APP_ID/review-status/

看看哪里写着“您想让这个应用程序及其所有实时功能向公众开放吗?”,将其设置为“是”。(您可能需要插入联系电子邮件才能访问此选项)。

或者,如果您还不想公开应用程序,请邀请测试人员成为应用程序的管理员/开发人员/测试人员。此人需要先接受您的邀请才能使用它。