2013-03-26 38 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; 
     } 
    } 
} 

更新: 一個朋友勸我檢查,如果選擇在鏈接的二進制文件確實存在。我按照這裏的說明找到查找器中調試二進制文件的位置:Where is my application binary in XCode? 然後,我右鍵單擊MyApp.app並選擇「顯示軟件包內容」。找到二進制文件(它是列表中最大的文件),將其拖入Vim並搜索「fberrorShouldNotifyUser」。我找不到這個選擇器或任何FBError選擇器。 我也嘗試清除XCode的派生數據 - 仍然沒有運氣。

更新#2: 呃,有時候你完全錯過了明顯的答案。事實證明,我沒有爲我的調試版本正確設置-ObjC標誌。見截圖:

Missing ObjC Flag

感謝d.kendall你爲我再次檢查。

回答

18

您需要將-ObjC添加到項目的構建設置中的「其他鏈接器標誌」。

+0

感謝您的建議 - 我已經在「其他鏈接器標誌」中嘗試了-ObjC和-all_load,但我仍然卡住了。 – 2013-04-04 18:03:51

+0

好的 - 謝謝你讓我再次檢查一遍。事實證明,我已經爲調試和發佈設置了標誌,但沒有發佈標題爲「Any Architecture | Any SDK」的子標籤。呃,不能相信我之前錯過了這個。謝謝!!!! – 2013-04-04 18:15:23

+1

你能解釋一下爲什麼它有幫助嗎? – expert 2013-08-29 10:51:03

1

您是否將3.2.1 sdk安裝到不同的目錄中(而不是覆蓋3.1 sdk)?如果是這樣,xcode可能會鏈接舊版本。你能否證實在Xcode的框架路徑:

  1. 在項目導航您添加Facebook的框架,右鍵 - >在Finder中顯示並驗證它打開3.2.1 SDK的位置;
  2. 在您的目標的構建設置中,搜索「framework」並驗證Framework搜索路徑僅包含3.2.1 sdk路徑 - 我發現它可以記住舊的框架位置並使用錯誤的路徑。
+0

感謝您的幫助! 1.已驗證 - 它指向3.2.1 sdk位置。 2.框架搜索路徑如下所示:$(繼承),「$(SRCROOT)」。在安裝3.2.1之前,我拋棄了3.1的舊副本。此外,我的代碼是使用新的3.2.1 FBWebDialogs的東西,我認爲如果xcode連接到舊版本不會工作? – 2013-04-01 19:20:12

相關問題