2013-03-26 4 views
12

FacebookのiOS SDK 3.1から3.2.1に私のアプリケーションをアップグレードしたばかりで、新しいエラー処理を利用しようとしています。 NSErrorの新しいFBErrorカテゴリコードは一番下にあります。それは罰金コンパイルしますが、FBのエラーが発生したとき、私は、実行時に次を得る:FacebookのiOS SDK 3.2.1 - [NSError fberrorShouldNotifyUser]:インスタンスに送信されたセレクタが認識されない

- [NSError fberrorShouldNotifyUser]: unrecognized selector sent to instance 

このカテゴリはFacebookSDK静的ライブラリからリンク取得されていないリンカエラー、のように思えます。私はターゲットの他のリンカフラグの下に-ObjCと-all_loadの両方のフラグを追加しようとしました。私はこれを読んだ:http://developer.apple.com/library/mac/#qa/qa1490/しかしまだ運がない。

基本的に同じコードがFacebookのサンプルプロジェクトでうまく動作します。ご意見ありがとうございます。

// Open the Facebook session. 
- (void)openSession { 
    NSArray *permissions = [[NSArray alloc] initWithObjects:@"email", nil]; 

    // Open or re-open the active session 
    [FBSession openActiveSessionWithReadPermissions:permissions 
            allowLoginUI:YES 
           completionHandler:^(FBSession *session, FBSessionState state, NSError *error) { 
     [self sessionStateChanged:session state:state error:error]; 
    }]; 
} 

- (void)handleAuthError:(NSError *)error{ 
    NSString *alertMessage, *alertTitle; 

    if (error.fberrorShouldNotifyUser) { 
     // If the SDK has a message for the user, surface it. This conveniently 
     // handles cases like password change or iOS6 app slider state. 
     alertTitle = @"Something Went Wrong"; 
     alertMessage = error.fberrorUserMessage; 
    } else if (error.fberrorCategory == FBErrorCategoryAuthenticationReopenSession) { 
     // It is important to handle session closures as mentioned. You can inspect 
     // the error for more context but this sample generically notifies the user. 
     alertTitle = @"Session Error"; 
     alertMessage = @"Your current session is no longer valid. Please log in again."; 
    } else if (error.fberrorCategory == FBErrorCategoryUserCancelled) { 
     // The user has cancelled a login. You can inspect the error 
     // for more context. For this sample, we will simply ignore it. 
     NSLog(@"user cancelled login"); 
    } else { 
     // For simplicity, this sample treats other errors blindly, but you should 
     // refer to https://developers.facebook.com/docs/technical-guides/iossdk/errors/ for more information. 
     alertTitle = @"Unknown Error"; 
     alertMessage = @"Error. Please try again later."; 
     NSLog(@"Unexpected error:%@", error); 
    } 

    if (alertMessage) { 
     [[[UIAlertView alloc] initWithTitle:alertTitle 
           message:alertMessage 
           delegate:nil 
         cancelButtonTitle:@"OK" 
         otherButtonTitles:nil] show]; 
    } 

} 

// Handle Facebook session state changed 
- (void)sessionStateChanged:(FBSession *)session 
         state:(FBSessionState)state 
         error:(NSError *)error { 
    if (error) { 
     [self handleAuthError:error]; 
    } else { 
     switch (state) { 
      case FBSessionStateOpen: 
       [self onSessionOpen:session]; 
       break; 
      case FBSessionStateOpenTokenExtended: 
       [self onSessionOpen:session]; 
       break; 
      case FBSessionStateClosedLoginFailed: 
       [self onSessionClose:error]; 
       break; 
      case FBSessionStateClosed: 
       // No-op 
       // See: https://developers.facebook.com/docs/reference/ios/3.1/class/FBSession 
       // Session is closed but token is still cached for later use. 
       break; 
      default: 
       NSLog(@"sessionStateChanged: unknown state: %d", state); 
       break; 
     } 
    } 
} 

UPDATE: 友人はセレクタが実際にリンクされたバイナリに存在する場合、私がチェックすることをお勧め。私はここで指示に従って、ファインダ内のデバッグバイナリの場所を見つけました:Where is my application binary in XCode? 次に、MyApp.appを右クリックし、 "Show Package Contents"を選択しました。バイナリファイル(リストの中で最大のファイル)を見つけ、Vimにドラッグして "fberrorShouldNotifyUser"を探しました。このセレクタやFBErrorセレクタが見つかりませんでした。 私はXCodeの派生データをクリアしようとしました - まだ運がありません。

UPDATE#2: まあ、時には明らかな答えが間違っています。私のデバッグビルドに-ObjCフラグが正しく設定されていないことが判明しました。スクリーンショットを参照してください。

Missing ObjC Flag

おかげで、私は再びこれをチェックするために取得するためd.kendallします。

答えて

18

プロジェクトのビルド設定で「その他のリンカフラグ」に-ObjCを追加する必要があります。

+0

提案をありがとう - 私はすでに "他のリンカーフラグ"で-ObjCと-all_loadの両方を試しましたが、まだ固執しています。 –

+0

Ok - これをもう一度確認してくれてありがとう。それは私がデバッグとリリースのために設定されたフラグを持っていたが、リリースのサブタブの下に "Any Architecture | Any SDK"というタイトルではないことが判明した。ああ、私がこれを逃したのは信じられない。ありがとう!!!! –

+1

なぜそれが助けになったのか教えてください。 – expert

1

3.1.1 SDKを上書きするのではなく、別のディレクトリに3.2.1 SDKをインストールしましたか?もしそうなら、xcodeが古いバージョンをリンクしている可能性があります。

  1. Facebookフレームワークを追加したプロジェクトナビゲータで、Finderで右クリック→[表示]をクリックし、3.2.1 SDKの場所を開いていることを確認します。
  2. 対象のビルド設定で「フレームワーク」を検索し、Framework Search Pathsに3.2.1 SDKパスのみが含まれていることを確認します。古いフレームワークの場所を覚えて間違ったパスを使用できることがわかりました。
+0

ありがとうございました! 1.検証済み - 3.2.1 SDKの場所を指しています。 2.フレームワーク検索パスは、$(継承)、 "$(SRCROOT)"のようになります。 3.2.1をインストールする前に、3.1の古いコピーを破棄しました。また、私のコードでは、新しいバージョンの3.2.1 FBWebDialogsを使用しています。これは、xcodeが古いバージョンでリンクしていた場合にはうまくいかないと思いますか? –

関連する問題