繁体   English   中英

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

[英]iOS Facebook SDK 3.1 openActiveSessionWithReadPermissions: Detect when user is not granting access

我需要知道用户在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 grantedBOOL granted

@ 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];
    }];   
}

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

- (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.
                           }];
                      }];
}

希望这可以帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM