Facebook iOS SDK 3.2.1 - [NSError fberrorShouldNotifyUser]:无法识别的选择器发送到实例 [英] Facebook iOS SDK 3.2.1 - [NSError fberrorShouldNotifyUser]: unrecognized selector sent to instance

查看:174
本文介绍了Facebook iOS SDK 3.2.1 - [NSError fberrorShouldNotifyUser]:无法识别的选择器发送到实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I just upgraded my app from Facebook iOS SDK 3.1 to 3.2.1 and I'm trying to take advantage of the new error handling provided by the new FBError category on NSError. The code is at the bottom. It compiles fine, but when a FB error occurs, I get the following at run time:

- [NSError fberrorShouldNotifyUser]: unrecognized selector sent to instance

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

This seems like a linker error, where the category is not getting linked in from the the FacebookSDK static library. I tried adding both the -ObjC and -all_load flags under the other linker flags in the target. I read this: http://developer.apple.com/library/mac/#qa/qa1490/ but still no luck.

基本相同的代码在Facebook提供的示例项目中运行良好。感谢您的任何建议。

Basically the same code works fine in the sample projects provided by Facebook. Thanks for any suggestions.

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

更新:
一位朋友建议我检查选择器是否实际存在于链接二进制文件中。我按照这里的说明在finder中找到调试二进制文件的位置: Where是我在XCode中的应用程序二进制文件?
然后,我右键单击MyApp.app并选择显示包内容。找到二进制文件(它是列表中最大的文件),将其拖入Vim并搜索fberrorShouldNotifyUser。我找不到这个选择器或任何FBError选择器。
我也尝试清除XCode的派生数据 - 仍然没有运气。

UPDATE: A friend advised that I check if the selector actually exists in the linked binary. I followed the instructions here to find the location of the debug binary in the finder: Where is my application binary in XCode? Then, I right-clicked on MyApp.app and chose "Show Package Contents". Found the binary file (it was the largest file in the list), dragged it into Vim and searched for "fberrorShouldNotifyUser". I couldn't find this selector or any of the FBError selectors. I also tried clearing XCode's derived data - still no luck.

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

UPDATE #2: Ugh, sometimes you totally miss the obvious answer. It turns out I didn't have the -ObjC flag properly set for my debug builds. See screenshot:

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

Thanks to d.kendall for getting me to check this again.

推荐答案

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

You need to add -ObjC to "other linker flags" in your project's build settings.

这篇关于Facebook iOS SDK 3.2.1 - [NSError fberrorShouldNotifyUser]:无法识别的选择器发送到实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆