0

I'm implementing Facebook SDK for a legacy iOS app written in Swift 2.2 using Xcode 7.3.1. I installed Swift version of the SDK using CocoaPods according to this tutorial.

When I try to build the project i receive this error:

FBSDKApplicationDelegate.m No visible @interface for 'UIApplication' declares the selector 'openURL:options:completionHandler:'

Here is the affected code in FBSDCoreKit:

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

How to solve this error without modifying Facebook SDK itself?

Jan Slominski
  • 2,968
  • 4
  • 35
  • 61

3 Answers3

2

I reported this issue 10 days ago but still no response https://github.com/facebook/facebook-sdk-swift/issues/122

  • I just switched to obj-c SDK for the project affected (due to deadline we couldn't migrate it to swift 3.0.X/Xcode 8.X.X on time) – Jan Slominski Jan 29 '17 at 11:13
0

This issue is caused by using Swift 2.2/Xcode 7.3.1 with the latest (v0.2.0 as I'm posting this anwser) Facebook SDK. After migrating to latest Swift/Xcode 8.2.1 the problem is not occurring.

Jan Slominski
  • 2,968
  • 4
  • 35
  • 61
0

You should update for this:

- (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
  });
}
Mario Jaramillo
  • 567
  • 6
  • 9