【问题标题】:Error: FBSDKApplicationDelegate.m No visible @interface for 'UIApplication' declares the selector 'openURL:options:completionHandler:'错误:FBSDKApplicationDelegate.m 没有可见的“UIApplication”@interface 声明选择器“openURL:options:completionHandler:”
【发布时间】:2017-06-05 12:22:17
【问题描述】:

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

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

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 本身的情况下解决此错误?

【问题讨论】:

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


【解决方案1】:

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

【讨论】:

  • 我刚刚为受影响的项目切换到 obj-c SDK(由于截止日期,我们无法按时将其迁移到 swift 3.0.X/Xcode 8.X.X)
【解决方案2】:

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

【讨论】:

    【解决方案3】:

    您应该为此更新:

    - (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
      });
    }
    

    【讨论】:

      猜你喜欢
      • 2016-12-28
      • 2022-08-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多