0
votes

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?

3
Thanks, I would prefer not to touch the SDK itself (edited my question, sorry for omitting that part) - Jan Slominski

3 Answers

2
votes
0
votes

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.

0
votes

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