【问题标题】:Facebook cocoapods 'sharedApplication' is unavailable: not available on iOS (App Extension)Facebook cocoapods 'sharedApplication' 不可用:在 iOS 上不可用(应用程序扩展)
【发布时间】:2018-06-15 19:22:10
【问题描述】:

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

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

关于 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

【问题讨论】:

    标签: ios swift facebook fbsdk


    【解决方案1】:

    您可以将以下块添加到您的 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
    

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

    【讨论】:

    • 这应该是正确答案!!!谢谢,迈克尔!
    【解决方案2】:

    这对我有帮助: Pods 项目 -> 选择包含此错误的 Target -> Build Settings -> 设置 Require Only App-Extension-Safe API 改为

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

    【讨论】:

    • 如何用swift包做到这一点
    【解决方案3】:

    尝试评论OneSignalNotificationServiceExtension target & pod ,清理,安装并再次运行

    【讨论】:

    • 嗨,我替换了那些依赖项,清理并尝试构建,但仍然得到相同的错误。
    • 在app target下制作pods
    • 尝试评论 OneSignalNotificationServiceExtension 目标和 pod ,清理,安装并再次运行
    • 如果我的应用需要 OneSignal 怎么办?
    • 是否有任何解决方案可以在不从目标中删除 OneSignalExtension 的情况下完成?
    【解决方案4】:

    我有同样的问题,我解决了 将require only App-Extension-Safe Api 设置为no 似乎所有的 Facebook pod require only App-Extension-Safe Api 都设置为是,所以我必须为所有 xcodeproject,target,all facebook pods 设置否, 您可以找到require only App-Extension-Safe Api in build setting for pods,target,and project 重要提示,当您重新安装 pod 时,它们会重置为 yes

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-09
      • 2015-05-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多