Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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
like image 637
Pavan Jadhav Avatar asked Sep 25 '18 17:09

Pavan Jadhav


4 Answers

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.

like image 73
Allison Avatar answered Oct 23 '22 17:10

Allison


I've found a working solution here: https://ahbou.org/post/169786332682/shared-is-unavailable-use-view-controller-based

It sounds like this:

Select the Pods Project on the left menu

Select the Pod that’s incompatible with the extension in targets list

Select Build Settings

Set Require Only App-Extension Safe API to NO

like image 7
Oksana Fedorchuk Avatar answered Oct 23 '22 15:10

Oksana Fedorchuk


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.

like image 3
Augie Avatar answered Oct 23 '22 16:10

Augie


Remove Extension check from that files Target membership.

enter image description here

like image 1
Uday Babariya Avatar answered Oct 23 '22 16:10

Uday Babariya