4

openActiveSessionWithReadPermissions の実行中に、ユーザーがアプリへの Facebook アクセスを許可していないことを知る必要があります。(設定 -> Facebook -> マイアプリでスイッチが「オフ」に設定されていることを意味する許可されていません。)

許可されていない場合のエラーは次のとおりです。

Error Domain=com.facebook.sdk Code=2 "The operation could not be completed. (com.facebook.sdk error 2.)" UserInfo=0x1fd46780 {com.facebook.sdk:ErrorLoginFailedReason=com.facebook.sdk:ErrorLoginFailedReason }

比較のために、ネットワークがない場合のエラーを次に示します。

Error Domain=com.facebook.sdk Code=2 "The operation could not be completed. (com.facebook.sdk error 2.)" UserInfo=0x1edf2eb0 {com.facebook.sdk:ErrorLoginFailedReason=com.facebook.sdk:ErrorLoginFailedReason , com.facebook.sdk:ErrorInnerErrorKey=Error Domain=NSURLErrorDomain Code=-1009 "インターネット接続がオフラインのようです。" UserInfo=0x1ed47a20 {NSErrorFailingURLKey=https://api.facebook.com/method/auth.iosauthorizeapp, NSErrorFailingURLStringKey=https://api.facebook.com/method/auth.iosauthorizeapp, NSLocalizedDescription=インターネット接続がオフラインのようです。 }}

ユーザーが許可されていないことを検出する確実な方法はありますか? UserInfo ディクショナリでエラー コード 2 と 1 つのキーと値のペアを探すだけですか?

Facebookが私たちに「いいね!」をくれたらいいBOOL grantedのにACAccountStoreRequestAccessCompletionHandler

4

2 に答える 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];
    }];   
}
于 2013-01-10T06:02:15.643 に答える
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.
                           }];
                      }];
}

お役に立てれば。

于 2014-05-22T13:09:08.753 に答える