我剛剛將我的應用程序從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標誌。見截圖:
感謝d.kendall你爲我再次檢查。
感謝您的建議 - 我已經在「其他鏈接器標誌」中嘗試了-ObjC和-all_load,但我仍然卡住了。 – 2013-04-04 18:03:51
好的 - 謝謝你讓我再次檢查一遍。事實證明,我已經爲調試和發佈設置了標誌,但沒有發佈標題爲「Any Architecture | Any SDK」的子標籤。呃,不能相信我之前錯過了這個。謝謝!!!! – 2013-04-04 18:15:23
你能解釋一下爲什麼它有幫助嗎? – expert 2013-08-29 10:51:03