I have a dynamic framework that is shared between an iOS application and an extension. There is some code in that framework that references UIApplication
, that is of course, not usable in an extension. Those calls are completely isolated and so I am not worried about them causing problems with my extension.
Since there isn't a flag specified in the warning message, perhaps there isn't way to do it, but how do I suppress warning: linking against dylib not safe for use in application extensions
when building my project?
对于您的 watch/today-widget 扩展目标(因此不是您的应用程序或库目标),进入项目设置并将构建设置APPLICATION_EXTENSION_API_ONLY
/ Require Only App-Extension-Safe API
更改为NO 。
I think you can use embedded framework to share code between your app extension and its containing app. But you have to be careful that your framework doesn't contain apis which are unavailable to extensions. See Some APIs Are Unavailable to App Extensions and Using an Embedded Framework to Share Code .
If your framework doesn't contain such apis don't forget to set Require Only App-Extension-Safe API
to YES in your framework target's Build Settings
.
As a second way to share source files between application and extension, you don't have to create a separate framework target. You can just share source files by targeting both two projects.
Short answer: there isn't really a way to do.
What I ended up doing was refactoring my code to pull out the pieces that were common to my extension on and my dynamic frame so that my extension could safely reference those pieces independent of the phone-specific code.
I ended up doing this because sometime in the future I will need to submit this to the App Store and Apple's guidelines seem pretty clear that referencing UIApplication
is a pretty big no-no.
Sometimes 'Nanny' doesn't know best.
You can avoid linking to UIApplication.shared
and just call the methods dynamically in your framework.
class Application {
static var shared: UIApplication {
let sharedSelector = NSSelectorFromString("sharedApplication")
guard UIApplication.responds(to: sharedSelector) else {
fatalError("[Extensions cannot access Application]")
}
let shared = UIApplication.perform(sharedSelector)
return shared?.takeUnretainedValue() as! UIApplication
}
}
This allows you to effectively call UIApplication.shared
(just call Application.Shared
) without making the linker freak out.
You will get a crash if you try to call this from an extension.
I try with this use_frameworks! :linkage => :static
use_frameworks! :linkage => :static
but please make sure that your project build successfully and unit tests run successfully.
Add this to your Podfile, change 'ExtensionName' with your extension target name
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
if target.name == 'ExtensionName'
config.build_settings['APPLICATION_EXTENSION_API_ONLY'] = 'YES'
else
config.build_settings['APPLICATION_EXTENSION_API_ONLY'] = 'NO'
end
end
end
I have a dynamic framework that is shared between an iOS application and an extension. There is some code in that framework that references UIApplication
, that is of course, not usable in an extension. Those calls are completely isolated and so I am not worried about them causing problems with my extension.
Since there isn't a flag specified in the warning message, perhaps there isn't way to do it, but how do I suppress warning: linking against dylib not safe for use in application extensions
when building my project?
All above Solutions are not working in my case.. I'm working on a framework & when add it to any project then need first to set "Require Only App-Extension-Safe API" to "NO" each and every time into related project.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.