我在共享扩展中使用下面的豆荚。编译器一直显示错误: sharedApplication‘不可用:在iOS (应用程序扩展)上不可用--在适当的地方使用基于视图控制器的解决方案。在UIApplication sharedApplication行上的每个库中
目标->构建设置->只需要应用扩展安全的API ->否
我的个人档案:
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发布于 2021-08-02 04:12:56
升级到我的Swift软件包中的Xcode 13之后,就开始碰到这个问题了。SPM没有和豆荚相同的目标会员选项,所以Uday的回答不太适合我。从本质上讲,这个问题是SPM包现在(显然?)为所有可用目标编译,而不管它们是否实际链接。因此,如果您的代码无法在您从未打算使用的地方工作,那么您就无法构建您的代码。
我的解决方案是分叉包,并将出现此问题的类标记为扩展名中不可用的类:
NS_EXTENSION_UNAVAILABLE("xxxx not supported in extensions (deprecated use of UIApplication shared)")
@interface xxxx : UIView
...或相当于在Swift中:
@available(iOSApplicationExtension, unavailable)
class xxxx {
...您也可以将这些可用性宏应用于特定的函数/变量,但对我来说,只将其抛到整个类中是不那么有害的,因为我从来不打算在扩展中使用这些库。
发布于 2021-11-11 14:20:40
我在这里找到了一个可行的解决方案:https://ahbou.org/post/169786332682/shared-is-unavailable-use-view-controller-based
听起来是这样的:
选择左侧菜单上的Pods项目
选择与目标列表中的扩展不兼容的Pod
选择生成设置
将只需要应用程序的扩展安全API设置为NO
发布于 2018-09-25 17:27:06
一些Pods不能用于扩展。我在IQKeyboardManager中遇到了同样的问题。https://github.com/hackiftekhar/IQKeyboardManager/issues/410
在我使用的扩展类型中,sharedApplication或shared不可用。
https://stackoverflow.com/questions/52503400
复制相似问题