Facebook的iOS SDK 3.2.1 – :无法识别的select器发送到实例

我刚刚将我的应用程序从Facebook iOS SDK 3.1升级到3.2.1,并试图利用NSError上新的FBError类别提供的新的error handling。 代码在底部。 它编译得很好,但是当发生FB错误​​时,我在运行时得到以下内容:

- [NSError fberrorShouldNotifyUser]: unrecognized selector sent to instance 

这看起来像一个链接器错误,其中类别没有从FacebookSDK静态库链接。 我尝试在目标中的其他链接器标志下添加-ObjC和-all_load标志。 我读了这个: http : //developer.apple.com/library/mac/#qa/qa1490/但仍然没有运气。

基本上相同的代码在Facebook提供的示例项目中工作正常。 感谢您的任何build议。

 // 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; } } } 

更新:一个朋友build议我检查select器是否确实存在于链接的二进制文件中。 我按照这里的说明来查找debugging器中的debugging二进制文件的位置: XCode中的应用程序二进制文件在哪里? 然后,我右键单击MyApp.app并select“显示包装内容”。 find二进制文件(这是列表中最大的文件),将其拖入Vim并search“fberrorShouldNotifyUser”。 我找不到这个select器或任何FBErrorselect器。 我也尝试清除XCode的派生数据 – 仍然没有运气。

更新#2:呃,有时你完全错过了明显的答案。 事实certificate,我没有正确设置我的debugging版本的-ObjC标志。 看截图:

缺少ObjC标志

感谢d.kendall让我再次检查这个。

您需要将-ObjC添加到项目的构build设置中的“其他链接器标志”。

你是否将3.2.1 sdk安装到不同的目录中(而不是覆盖3.1 sdk)? 如果是这样,有可能xcode链接旧版本。 你可以通过以下方式确认xcode中的框架path:

  1. 在添加Facebook框架的项目导航器中,右键单击 – >在Finder中显示并validation它打开3.2.1 sdk位置; 和,
  2. 在您的目标的构build设置中,search“框架”并validation框架searchpath仅包含3.2.1 sdkpath – 我发现它可以记住旧的框架位置并使用错误的path。