簡體   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