首页 文章

iOS Facebook SDK 3.1 openActiveSessionWithReadPermissions:检测用户何时未授予访问权限

提问于
浏览
4

我需要知道用户在openActiveSessionWithReadPermissions执行期间何时没有授予Facebook访问我的应用程序的权限 . (未授予意味着在“设置” - >“Facebook->我的应用程序”下将开关设置为“关闭” . )

以下是未授予时的错误:

Error Domain = com.facebook.sdk Code = 2“无法完成操作 . (com.facebook.sdk error 2.)”UserInfo = 0x1fd46780 {com.facebook.sdk:ErrorLoginFailedReason = com.facebook.sdk: ErrorLoginFailedReason}

为了比较,这是没有网络的错误:

Error Domain = com.facebook.sdk Code = 2“无法完成操作 . (com.facebook.sdk error 2.)”UserInfo = 0x1edf2eb0 {com.facebook.sdk:ErrorLoginFailedReason = com.facebook.sdk: ErrorLoginFailedReason,com.facebook.sdk:ErrorInnerErrorKey = Error Domain = NSURLErrorDomain Code = -1009“Internet连接似乎处于脱机状态 . ” UserInfo = 0x1ed47a20 {NSErrorFailingURLKey = https://api.facebook.com/method/auth.iosauthorizeapp,NSErrorFailingURLStringKey = https://api.facebook.com/method/auth.iosauthorizeapp,NSLocalizedDescription = Internet连接似乎处于脱机状态 . }}

是否有一种万无一失的方法来检测用户何时未被授予?我只是在UserInfo字典中查找错误代码2和一个键/值对吗?

我希望Facebook在 ACAccountStoreRequestAccessCompletionHandler 中给我们一个 BOOL granted .

2 回答

  • 0

    @ peter-warbo:我找不到好的解决方案 . 我正在使用这个:

    [FBSession openActiveSessionWithReadPermissions:FACEBOOK_READ allowLoginUI:YES 
        completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
    
        // find error for not granted
        if(error && error.code == 2) {
            NSDictionary *userInfo = error.userInfo;
            if(userInfo && userInfo.count == 1) {
                [self fallbackLogin];
                return;
            }
        }
        [self sessionStateChanged:session state:state error:error];
    }];
    
    - (void)fallbackLogin {
    
        // use deprecated
        [FBSession openActiveSessionWithPermissions:FACEBOOK_READ allowLoginUI:YES
    completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
              [self sessionStateChanged:session state:state error:error];
        }];   
    }
    
  • 0

    您可以使用以下代码检查权限:

    - (void)checkForPermissions {
        // We will request the user's public profile and the user's birthday
        // These are the permissions we need:
        NSArray *permissionsNeeded = @[@"basic_info", @"email"];
        // Request the permissions the user currently has
        [FBRequestConnection startWithGraphPath:@"/me/permissions"
                              completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
                              //If there is error, handle it accordingly.
    
                              //Results contains all the permissions user has granted the app.
                              //If you do not have the desired permissions, reauthorize the app
                              // Ask for the missing permissions
                              //requestPermissions = array of permissions to be asked
                              [FBSession.activeSession
                               requestNewReadPermissions:requestPermissions
                               completionHandler:^(FBSession *session, NSError *error) {
                                   //Handle the session object as per your requirements.
                               }];
                          }];
    }
    

    希望这可以帮助 .

相关问题