ios - Facebook iOS SDK 3.2.1 - [NSError fberrorShouldNotifyUser] : unrecognized selector sent to instance

标签 ios runtime-error facebook-ios-sdk objective-c-category

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

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

更新: 一位 friend 建议我检查选择器是否确实存在于链接的二进制文件中。我按照此处的说明在查找器中找到调试二进制文件的位置:Where is my application binary in XCode? 然后,我右键单击 MyApp.app 并选择“显示包内容”。找到二进制文件(它是列表中最大的文件),将它拖到 Vim 中并搜索“fberrorShouldNotifyUser”。我找不到这个选择器或任何 FBError 选择器。 我也尝试清除 XCode 的派生数据 - 仍然没有成功。

更新#2: 呃,有时候你完全错过了明显的答案。事实证明我没有为我的调试版本正确设置 -Objcflags。看截图:

Missing ObjC Flag

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

最佳答案

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

关于ios - Facebook iOS SDK 3.2.1 - [NSError fberrorShouldNotifyUser] : unrecognized selector sent to instance,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15640510/

相关文章:

iOS:启动具有多个收件人的消息应用程序

ios - 如果登录成功,如何关闭登录 View ? swift

ios - 如何使用 FBLoginView 检查 Facebook 登录?

ios - Facebook iOS SDK 'one-time' 授权

iOS - 可扩展和重新排序TableView

ios - 上传 ipa 文件的 Crashlytics 不会上传 DSYM 文件

java - 尝试使用 Double 与 double 计算用户输入

iOS UIPageViewController - 由于未捕获的异常 'Invalid parameter not satisfying: [views count] == 3' 而终止应用程序

haskell - 如何处理 Haskell 中的运行时错误?

ios - Facebook iOS SDK : Tagging friends?