Use Cocoapods with an App Extension

泄露秘密 提交于 2019-11-27 10:09:27
LeChatNoir

The proper way to do this is to update your podfile to add just 1 line :

link_with 'yourApp', 'yourAppExtension'

and a pod update should resolve the issue.

EDIT (2015/03/10)

See new accepted answer. I tried it in a new project and it worked, although my test pods both used sharedApplication which is disallowed in extensions. The fact that they showed those errors means it linked properly. Way to go @LeChatNoir!


Success.

The solution is as follows: Once you have your app extension and it's bridging header in a project using cocoapods and you want to use one of those cocoapods libraries, trying to include the pod like #import <GPUImage/GPUImage.h> will fail with file not found.

First, make sure that you tell the app extension (click on your project file, then on the extension target) to link against libPods.a, much like your app target.

Next, in your actual project (click on your project file, then on the project file again in the "Project" section of the inner sidebar) under the Info tab, set the configuration of the extension for Debug, Release, and Inhouse to use the "Pods" configuration from the dropdown. Pod Install will not do this for you, so you will need to do it yourself.

Lastly, make sure that both the Pods project's targets and your project's targets have all the architectures you need to build for in the Valid Architectures variable or you will get the ever-fun undefined symbols error.

This should work and allow you to import the pods of your choice like normal.


EDIT (2014/10/14): As an aside, since you may also be including Objective-C files from within your own project code in the Swift extension, you should make sure that any .m files you put in the bridging header are also compiled by the extension target. You can either do this from the compile sources menu for the target or in the .m file itself using the "Target Membership" section of the right sidebar in Xcode.

The above answers will work, but I only wanted a couple pods in my extension, so I did the following to my Podfile:

target '[Main App Target Name]' do
        pod ...
        pod ...
        pod ...
end

target '[Extension Target Name]' do
        pod ...
end

And then a pod install will do it!

link_with, you will not use it anymore.

Invalid Podfile file: [!] The specification of link_with in the Podfile is now unsupported, please use target blocks instead..

Below is the perfect answe, tested also.

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, ‘9.0’
use_frameworks!
inhibit_all_warnings!

target 'DemoTodayWidget' do
    pod 'Reachability',                         '~> 3.2'
end

target 'My Widget' do
    pod 'Reachability',                         '~> 3.2'
end
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!