Error: FBSDKApplicationDelegate.m No visible @interface for 'UIApplication' declares the selector 'openURL:options:completionHandler:'
Error: FBSDKApplicationDelegate.m No visible @interface for 'UIApplication' declares the selector 'openURL:options:completionHandler:'
我正在使用 Xcode 7.3.1 为使用 Swift 2.2 编写的遗留 iOS 应用程序实施 Facebook SDK。我安装了 Swift version of the SDK using CocoaPods according to 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 本身的情况下解决这个错误?
这个问题是由于使用 Swift 2.2/Xcode 7.3.1 和最新的(我发布这个 anwser 时是 v0.2.0)Facebook SDK 引起的。迁移到最新的 Swift/Xcode 8.2.1 后,问题没有发生。
我在 10 天前报告了这个问题,但仍然没有回复 https://github.com/facebook/facebook-sdk-swift/issues/122
你应该为此更新:
- (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
});
}
我正在使用 Xcode 7.3.1 为使用 Swift 2.2 编写的遗留 iOS 应用程序实施 Facebook SDK。我安装了 Swift version of the SDK using CocoaPods according to 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 本身的情况下解决这个错误?
这个问题是由于使用 Swift 2.2/Xcode 7.3.1 和最新的(我发布这个 anwser 时是 v0.2.0)Facebook SDK 引起的。迁移到最新的 Swift/Xcode 8.2.1 后,问题没有发生。
我在 10 天前报告了这个问题,但仍然没有回复 https://github.com/facebook/facebook-sdk-swift/issues/122
你应该为此更新:
- (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
});
}