I am working on iOS 8 extension. I read many manuals and all of them just show how simple add extension to your app, and seems that's enough.
But here are many pitfalls:
After adding your extension you will need to import some of your classes to view controller that were created when you added new extension target. The big use here that you will need add all of them and if you have huge project it's not a simple task. Solution can be select extension target then in Build Phases -> Compile Sources press plus button and add all .m files to your target using hot key CMD+A.
After adding all files you can see that some of method wont work, and you can see this error: 'sharedApplication' is unavailable: not available on iOS (App Extension)
so the solution can be a macros that check ifndef Extension
then we can invoke sharedApplication
code.
#import <Foundation/Foundation.h>
vs #import <UIKit/UIKit.h>
. So I have not figured out with this issue but when I replaced Foundation
with UIKit
it works for me and all related issues go away.
link_with 'ProjectTarged', 'ExtensionTarget'
to Pod file and make pod install
again to bind your libraries with new extension target.So this is a main points I faced with. Maybe someone can suggest how to solve that issue, as I said I just import one needed file to extension view controller. The imported file contain some libraries like AFNetworking
, RestKit
and other nested classes from the main project. I need this class to invoke few methods with passing data from extension to my backend server. So one file but many issues.
you can use this in your Podfile to prevent "Require only App-Extension-Safe API". Just put it to the end of your Podfile.
post_install do |installer_representation|
installer_representation.project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['APPLICATION_EXTENSION_API_ONLY'] = 'NO'
end
end
end
1) You only need to add files to the extension target that you actually intend on using. I would recommend only pulling over what you need by finding the files and in the File Inspector, adding them to both targets.
2) Yep that's right. You'll need to update libraries that check that for you or fork them and fix them yourself.
3) I think you're referring to the default templates when creating one of the app extensions. Yes, you need to use UIKit not Foundation. Foundation will work for iOS or OS X, but clearly isn't enough if you are making a UIKit application.
4) The link_with command will make all pods in your Podfile link to all of the targets listed. If that's what you need, then, fine, do that. If you just need a small subset of pods for your extension, use the following:
target 'whateverTarget', :exclusive => true do
pod 'SomePod'
end
To remove sharedApplication
issue from CocoaPods Libraries you just need to change Build Options within Build Settings for your pod.
Just type to search Require Only App-Extension-Safe API
and then change the value to NO
as it is on the image below:
Propably you will need to do this for every of your pods.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With