3
votes

I am using following pods in a Share Extension. The complier is keep showing error: sharedApplication' is unavailable: not available on iOS (App Extension) - Use view controller based solutions where appropriate instead. in every library on [UIApplication sharedApplication] line

  1. I installed all libraries in the Share Extension target.

  2. I have four targets including Share-Extension in my project and I have set “AppExtension flag is NO” for each target. Still appear errors.

Target -> Build Settings -> Require Only AppExtension-Safe API -> NO

My Podfile:

platform :ios, '11.2'
def shared_pods
use_frameworks!
source 'https://github.com/CocoaPods/Specs.git'

pod 'XMPPFramework', :git => "https://github.com/robbiehanson/XMPPFramework.git", :branch => 'master'

pod 'MBProgressHUD'  

pod 'GoogleMaps'

pod 'GooglePlaces'

pod 'AccountKit'

pod 'Alamofire', '~> 4.5'

pod 'AlamofireImage', '~> 3.3'

pod 'SVProgressHUD'

pod 'SDWebImage', '~> 4.1.1'

pod 'AWSS3', '~> 2.6.0'

pod 'Fabric'

pod 'Crashlytics'

pod 'Firebase/Core'

pod 'Firebase/Messaging'

pod 'ReverseExtension'

end

target ‘Production' do
    shared_pods
end

target ‘Development’ do
    shared_pods
end

target ‘Testing’ do
    shared_pods
end
5
Please take the time to format the code in your question correctly. - Ashley Mills

5 Answers

3
votes

Some Pods can not be used in extensions. I ran into this exact same issue with IQKeyboardManager. https://github.com/hackiftekhar/IQKeyboardManager/issues/410

sharedApplication or shared are not available in the Extension type I was using.

1
votes

UIApplication.shared is not available in the App extension. so, in your podfile, remove the library that uses UIApplication.shared

0
votes

Remove Extension check from that files Target membership.

enter image description here

0
votes

Started hitting this issue after upgrading to Xcode 13 in my Swift Packages. SPM doesn't have the same target membership options as pods and so Uday's answer couldn't quite do it for me. This issue is, in essence, that SPM packages are now (apparently?) being compiled for all available targets regardless if they're actually linked or not. Thus, if your code doesn't work in some place you never intended to use it, you simply cannot build your code.

My solution was to fork the packages and mark the classes that had this issue as being unavailable in extension:

NS_EXTENSION_UNAVAILABLE("xxxx not supported in extensions (deprecated use of UIApplication shared)")
@interface xxxx : UIView
...

Or equivalently in Swift:

@available(iOSApplicationExtension, unavailable)
class xxxx {
...

You can also apply these availability macros to specific functions/variables but it was less invasive for me to just throw it on the entire class since I never intended to use these libraries in an extension anyways.

-2
votes

The problem is that the pod is written in a very early version of Swift (2?), and you are trying to use it under a more recent version. sharedApplication changed to shared quite a long time ago.

You need to obtain an updated version of the pod (if possible).