2013-03-26 36 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

相关问题