错误:FBSDKApplicationDelegate.m'UIApplication'没有可见的@interface声明选择器'openURL:options:completionHandler:'

时间:2017-01-20 13:30:27

标签: ios swift facebook swift2 facebook-sdk-4.x

我正在使用Xcode 7.3.1为使用Swift 2.2编写的旧版iOS应用程序实现Facebook SDK。我根据Swift version使用CocoaPods安装了SDK的this tutorial

当我尝试构建项目时,我收到此错误:

FBSDKApplicationDelegate.m'UIApplication'没有可见的@interface声明选择器'openURL:options:completionHandler:'

以下是FBSDCoreKit中受影响的代码:

NSOperatingSystemVersion iOS10Version = { .majorVersion = 10, .minorVersion = 0, .patchVersion = 0 };
if ([FBSDKInternalUtility isOSRunTimeVersionAtLeast:iOS10Version]) {
  [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:handler];
} 

如何在不修改Facebook SDK本身的情况下解决此错误?

3 个答案:

答案 0 :(得分:2)

我在10天前报告了此问题,但仍然没有回复https://github.com/facebook/facebook-sdk-swift/issues/122

答案 1 :(得分:0)

这个问题是由于使用Swift 2.2 / Xcode 7.3.1和最新的(v0.2.0,因为我发布了这个版本)Facebook SDK。迁移到最新的Swift / Xcode 8.2.1后,问题没有发生。

答案 2 :(得分:0)

你应该为此更新:

- (void)openURL:(NSURL *)url sender:(id<FBSDKURLOpening>)sender 
handler:(void(^)(BOOL))handler
{
  _expectingBackground = YES;
  _pendingURLOpen = sender;
  dispatch_async(dispatch_get_main_queue(), ^{
    // Dispatch openURL calls to prevent hangs if we're inside the 
current app delegate's openURL flow already
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_10_0
      [[UIApplication sharedApplication] openURL:url options:@{} 
completionHandler:handler];
#else
      BOOL opened = [[UIApplication sharedApplication] openURL:url];

      if ([url.scheme hasPrefix:@"http"] && !opened) {
    NSOperatingSystemVersion iOS8Version = { .majorVersion = 8, .minorVersion = 0, .patchVersion = 0 };
    if (![FBSDKInternalUtility isOSRunTimeVersionAtLeast:iOS8Version]) {
      // Safari openURL calls can wrongly return NO on iOS 7 so manually overwrite that case to YES.
      // Otherwise we would rather trust in the actual result of openURL
      opened = YES;
    }
  }
  if (handler) {
    handler(opened);
  }
#endif
  });
}