Facebook cocoapods 'sharedApplication' 不可用:在 iOS 上不可用(应用程序扩展)

Mat*_*ack 9 facebook ios swift fbsdk

我已经通过 cocoapods 安装了 facebook sdk,但出现以下错误:

'sharedApplication' 不可用:在 iOS(应用扩展)上不可用 - 在适当的情况下使用基于视图控制器的解决方案。

与 FBSDKCoreKit/FBSDKAppEvents.m 中的第 701 行有关

UIViewController *vc = [UIApplication sharedApplication].keyWindow.rootViewController.presentedViewController;

为什么会发生这种情况,我该如何解决?播客文件:

   # Uncomment the next line to define a global platform for your 
 project
 # platform :ios, '9.0'

 target 'testapp' do
# Comment the next line if you're not using Swift and don't want to use dynamic 

frameworks
  use_frameworks!

  # Pods for testapp

pod 'FLAnimatedImage', '~> 1.0'
pod 'SDWebImage', '~> 4.0'
pod 'FacebookLogin'
pod 'FacebookShare'
pod 'FacebookCore'

 pod 'OneSignal', '>= 2.5.2', '< 3.0'


  target 'testappTests' do
    inherit! :search_paths
    # Pods for testing
  end

target 'OneSignalNotificationServiceExtension' do
  pod 'OneSignal', '>= 2.5.2', '< 3.0'
end

  target 'testappUITests' do
    inherit! :search_paths
    # Pods for testing
  end

end
Run Code Online (Sandbox Code Playgroud)

小智 27

您可以将以下块添加到您的Podfile以编程方式解决此问题。

如果您正在使用 pod,您可以将以下块添加到您的Podfile以解决此问题:

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['APPLICATION_EXTENSION_API_ONLY'] = 'No'
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

这将为所有 pod 项目目标设置require only App-Extension-Safe Apito No,并且应该允许您的构建成功。


小智 16

这就是帮助我的原因: Pods项目 -> 选择包含此错误的目标->构建设置-> 将Require Only App-Extension-Safe API 设置No

您可能必须对其他 FB 框架执行相同的操作


Sh_*_*han 3

尝试注释OneSignalNotificationServiceExtensiontarget 和 pod ,清理,安装并再次运行