Facebook cocoapods 'sharedApplication' is unavailable: not available on iOS (App Extension)
Asked Answered
B

6

18

I have installed the facebook sdk via cocoapods but I get the below error:

'sharedApplication' is unavailable: not available on iOS (App Extension) - Use view controller based solutions where appropriate instead.

relating to line 701 in FBSDKCoreKit/FBSDKAppEvents.m

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

Why is this happening and how do I resolve it? podfile:

   # 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
Bodleian answered 5/1, 2018 at 23:35 Comment(0)
N
3

Try to comment OneSignalNotificationServiceExtension target & pod , clean , install and run again

Neuberger answered 5/1, 2018 at 23:39 Comment(3)
Hi, I replaced those dependencies, cleaned and tried to build but still get the same error.Bodleian
try to comment OneSignalNotificationServiceExtension target & pod , clean , install and run againNeuberger
Hi, I have removed One Signal from my project and that has resolved the issue, thank you!Bodleian
C
50

You can add the following block to your Podfile to address this programatically.

If you are using pods you can add the following block to your Podfile to address this issue:

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

This will set the require only App-Extension-Safe Api to No for all pod project targets and should allow your builds to succeed.

Confinement answered 27/6, 2019 at 11:10 Comment(0)
B
23

That's what helped me: Pods project -> select Target which contains this error -> Build Settings -> set Require Only App-Extension-Safe API to No

You might probably have to do the same for other FB frameworks

Bandit answered 7/5, 2018 at 23:45 Comment(0)
N
3

Try to comment OneSignalNotificationServiceExtension target & pod , clean , install and run again

Neuberger answered 5/1, 2018 at 23:39 Comment(3)
Hi, I replaced those dependencies, cleaned and tried to build but still get the same error.Bodleian
try to comment OneSignalNotificationServiceExtension target & pod , clean , install and run againNeuberger
Hi, I have removed One Signal from my project and that has resolved the issue, thank you!Bodleian
H
3

i had the same problem,i solved it by setting require only App-Extension-Safe Api to no it seemed that all the facebook pods require only App-Extension-Safe Api were set to yes so i have to set no for all xcodeproject,target,all facebook pods , you can find require only App-Extension-Safe Api in build setting for pods,target,and project important note when ever you reinstall pods they are reseted to yes

Handbook answered 16/6, 2018 at 13:8 Comment(0)
C
1

For the ones who need oneSignal in their project:

The problem is the place the oneSignal pods are added in the podfile. I had the below code in my podfile:


target 'my_app_name' do
  pods()

  target 'my_app_name_dev' do
    pods()
  end

  post_install do |installer|
    react_native_post_install(installer)
    __apply_Xcode_12_5_M1_post_install_workaround(installer)
    # require for m1 mac
    installer.pods_project.build_configurations.each do |config|
      config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
    end
  end

  target 'OneSignalNotificationServiceExtension' do
    pod 'OneSignalXCFramework', '>= 3.0', '< 4.0'
  end
end

The reason the project was failing to run was I had added the oneSignal lines inside the main project target (my_app_name target) while OneSignalNotificationServiceExtension is a separate target in the project, so I moved it out of my app target pods and it worked:

target 'OneSignalNotificationServiceExtension' do
  pod 'OneSignalXCFramework', '>= 3.0', '< 4.0'
end

target 'my_app_name' do
  pods()

  target 'my_app_name_dev' do
    pods()
  end

  post_install do |installer|
    react_native_post_install(installer)
    __apply_Xcode_12_5_M1_post_install_workaround(installer)
    # require for m1 mac
    installer.pods_project.build_configurations.each do |config|
      config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
    end
  end
  
end
Caleb answered 13/6, 2022 at 10:58 Comment(1)
Had exactly the same problem, with RNScreens yelling at me for some reason, but I just implemented Onesignal and this solved my issue. Thanks!Bridgers
S
0

If you have already tried other approaches and none of them working and if you are getting this error in your main project and not in your app extension then just make your method unavailable for app extension.

@available(iOSApplicationExtension, unavailable)
    static var getTopSafeArea: CGFloat {
        if let window = UIApplication.shared.windows.first(where: { $0.isKeyWindow }) {
            return window.safeAreaInsets.top
        }
        return 0
    }
Staphyloplasty answered 7/12, 2022 at 13:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.