Use Cocoapods with an App Extension - swift

I'm trying to build a photo App Extension in Xcode 6 Beta-6 that uses cocoapods libraries.
The bridging header that Xcode creates for the photo extension can't see anything from cocoapods.
For example: #import <GPUImage/GPUImage.h> results in the error "GPUImage/GPUImage.h" file not found.
I've tried every conceivable path for the import (with brackets and quotes) and have had almost no success. The exception is that for simple pods like SVProgressHUD, the following ugly terrible hack works:
#import "../Pods/SVProgressHUD/SVProgressHUD/SVProgressHUD.h".
But for GPUImage, it walks into the GPUImage.h header and decides it suddenly can't see GPUImageContext.h despite having no issue when this is imported with the bridging header for the normal swift code that is not part of the app extension.
What is different about the compilation of app extensions that is preventing the bridging header from behaving sanely?
Note:
I've read every possible permutation of this tutorial and it is not immediately applicable, just in case anyone thinks they have found the answer there.
Also, the problem described in this SO question may be related, but I asked this question anyway in case my issue is specific to app extensions.

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!

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.

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

Related

How to embed third party framework on ionic capacitor custom plugin?

I am developing an Ionic Capacitor plugin which imports 2 iOs .framework files and a .bundle that refers to one of this .framework files. The thing is that no matter how I link/embed and point/copy this files on the plugin project, xcode claims, on the app project, that it cant find the module in the swift file.
I already tried to add the files to the project, used the "Embedded binaries" option, linked libraries, allow non-modular includes (on build options menu), add the files to the headers (on build phases), and so on....
The line that xcode point the error is:
import OneFramework
And xcode claims:
No such module 'OneFramework'
I was expecting that when I add the plugin to my app project via npm, and later running a "$ rm -rf ios && ionic capacitor run ios" to run the app, xcode find all the modules of the plugin that I am trying to do.
I found the solution. To achieve this the first thing to know is that when you do npx #capacitor/cli plugin:generate what the CLI do for you is the generation of a cocoa pod. The root of this pod is the generated folder itself.
With that in mind, the next thing to do is to learn how to make pods, but i'll sumarize the principal aspects that led me to the success.
-First of all you open the *.xcworkspace. Followed by that, click on the "Add Files to Pod..." option and add your files. Please ensure that the "Copy files if needed" option is marked. Please refer to the picture below.
-Now its nice to create a folder for your .framework and another for the .bundle (if there are any) files. Do this by right clicking the Pods project and select the option "New group". Select a name like that is different from the pattern of xcode, it is nice to know that this folders are created by you.
-If you done this right, the frameworks you recently added to the project will appear on the pods project like this:
-Now, for your swift implementation find your files, drag your .frameworks that are on the pods project for the "Frameworks, Libraries and Embedded content" of the plugin project. The result will be something like this:
-Ok, files included and linked. Now we should let our cocoa pod know about this and declare this files. The file "YourAwesomePlugin.podspec" (located at the root of the plugin project) is the main entrance of the pod. In this file you will declare which files (.frameworks, .bundle, etc) belong to your pod and consequently will belong to your plugin when you npm install it. To declare this you'll need three directives:
s.vendored_frameworks = 'ios/Pods/YourFrameworkFolder/**'
s.resource = 'ios/Pods/YourResourceFolder/YourBundle.bundle'
s.xcconfig = {'ENABLE_BITCODE' => 'NO'} #This is mandatory on my case, but you need to evaluate if this options applies to your plugin.
-Now we hit play on the plugin project. To test on your app if the plugin is ok, you need to add the path of the root of the plugin project on the podfile of the pods project of the APP project. Like this:
-To install it you can go on Yourproject/ios/App and run pod install.
Please note that:
To declare the existence of your recently created plugin you you need to do some declarations as well, but this part is easy and already documented on capacitor/plugin docs.
The installation method via pod install that I suggested is for testing. It would be nice if you pack your plugin using npm and npm install it like all other plugins.
I dont have much knowledge on cocoapods like I wish, but this works and I think that is a clean solution. If not, please let me know.
If this answer is useful for you, please thumbs it up, it is a week of research and trying that I am sharing, along the time to write it all down.

Cocoapods import development pod into Swift

I have a development pod which contains Objective C code. I would like to import this into my Swift project. Previously, I just added the header files to the Bridging Header file and everything worked fine. Now I'd like to use the use_frameworks! flag to build the development pod as a dynamic framework.
When I do this, there are errors in the Xcode project.
Use of unresolved identifier...
However, when I control click the class name in Xcode, it correctly takes me to the source file.
My question is - when I have a development pod that uses Objective C and I add this to a Swift project using the use_frameworks! flag, how do I import my files into the Swift code? Do I need to create some kind of bridging header file or use any kind of import statement?

Tumblr integration in iPhone SDK

Using https://github.com/tumblr/TMTumblrSDK link, i am trying to integrate tumbler sdk and compile the Photosharing sample project under the Example folder. But i am getting the following error message:
diff: /../Podfile.lock: No such file or directory
I am not able to understand the pod file concept. Can anyone please explain me the proper steps that need to be followed to integrate this sdk in iOS app.
The targets in your xcode projects have a build phase to perform a lock file. But it seems like your xcode projects configurations are not referencing the user defined settings configured in Pods/Pods-libPods.xcconfig.
It looks like you are trying to link a Pod with specific targets in multiple xcodeprojs. If my assumption is correct, you are using the target attribute incorrectly. The target attribute creates a new static library within the Pods project that includes the Pods you configured within that target.
The default target for the Pods xcodeproj is libPods which generates the libPods.a static library. This is generated if you do not specify a target. So if you don't care about generating multiple static libaries in the Pods xcodeproj, don't bother defining a target and use the link_with attribute to link the default libPods target (static library) to the targets in your xcodeprojs.
check this link for further reading here

This target might include its own product

File .../FaceDeFace.app depends on itself.
This target might include its own product.
File .../FaceDeFace.app depends on itself.
This target might include its own product.
I have done my project in os Snow leopard but now my os version also changed and it is now 10.7.3. This is installed in my Imac machine. This app start first in MacBook but now I want to develop it in IMac. But the above error is shown so what i have to do. Though I have change all of my certificate, and all provisioning profiles newly.
Please help.
Thanks i advance.
Select the target in your Xcode project and click the Build Phases tab. Look at the Target Dependencies list; the target's product should not be listed there, but it sounds like it may have been added to that list by mistake. Also check the other areas in that same tab -- you don't want your product listed in Copy Bundle Resources or Link Binary With Libraries, either -- you obviously can't use the thing that you're building as a resource or library to build the product in the first place. That's what Xcode seems to be complaining about.
Ran across this issue using Xcode 7 (beta 1) when trying to build a Static Library target. Here was the error message from the build output:
Unable to run command 'CopySwiftLibs libMyStaticLibraryName.a' - this target might include its own product.
(I substituted libMyStaticLibraryName.a above in place of the actual name of my static library.)
The problem turned out to be that this static library target had the Embedded Content Contains Swift Code build setting (EMBEDDED_CONTENT_CONTAINS_SWIFT) set to YES, when in reality there was no Swift code associated with this target. Setting this to NO in Xcode fixed the issue.
Static libraries cannot include Swift code, so if this build setting is set it causes the error, even if there is no actual Swift code in the target.
In my case, very simple, please delete Universal target, then add new target.
That's all
In my case my project had submodule inside, so commands
git submodule add submoduleURL
git submodule init
git submodule update
solved this issue.
I had the same problem, when podspec file was incorrect. My mistake was that I didn't specify .h and .m extensions for source_files. Because of that .xib files were added twice. This is a correct example:
s.source_files = 'YourTarget/Classes/**/*.{h,m}'
s.resources = ['YourTarget/Classes/UIComponents/**/*.xib']
See https://guides.cocoapods.org/syntax/podspec.html#source_files

'libxml/xmlversion.h' file not found in xcode 4.2?

i am integrating twitter application in my application my application is created in xcode 4.2 using ARC when i implemented code for twitter from this code.
it worked perfectly when i just download the project & run it. when i integrate this twitter sdk code in my xcode 4.2 based application it gave me error of 'libxml/xmlreader.h' file not found i have solved it just changing header file this way #include <libxml2/libxml/xmlreader.h> but after changing this previous error was solved but than i got new error 'libxml/xmlversion.h' file not found. i tried to change header of file xmlreader.h but this file is not editable i have changed permissions for this file, too. but it didn't work. in the format like this #include <libxml2/libxml/xmlreader.h> but it doesn't work.
please tell me how to solve this error.
i have seen several question in stack overflow for some that kind of question
but they didn't work for me in xcode 4.2.
please guide me.
You need to put all the libxml headers on the include path. For Xcode do this by adding /usr/include/libxml2 to the header paths (that will pass -I/usr/include/libxml2 to the c compiler)
This is in the build settings tab in Search Paths -> Header Search Paths
Works for me.
Remember to add the library in Link Binary en Build Phases Section of the target project.
Go to Project -> Build Settings and search for "User Header Search Paths" key and add this value:
"${SDK_DIR}"/usr/include/libxml2
It works perfectly in my xcode 4.5 + iOS 6
I had the same problem as you. For me the problem was that I setup "Header Search Path" in Project Build Settings, but my Target Build Settings overrided that setting. I fixed this by adding $(inherited) line to Target Build Settings Header Search Paths.
If you're using CocoaPods and get this error, you'll have to fork the spec and the following lines to it:
s.libraries = 'xml2'
s.xcconfig = { 'HEADER_SEARCH_PATHS' => '$(SDKROOT)/usr/include/libxml2' }
You'll have to remove the Pod, then re-install it as well, with the podspec pointing to your fork. The reason why you have to fork the Pod is because the Target where you would normally change this is generated by CocoaPods when you perform pod install.
Note that if you have other libraries that the Pod depends on, include them on the s.libraries line.
Source for this fix in the CocoaPods issue "Pod Integration Issues"
In your build settings, for the key "Header Search Paths", add "$(SDK_DIR)"/usr/include/libxml2
I got the same errors and come to here, then I find the answer in below url
https://github.com/ZaBlanc/RaptureXML#adding-rapturexml-to-your-project
Hope this can help you, I've solved it now.
Add header search path as $(SDKROOT)/usr/include/libxml2
Be sure to use the non-recursive option when you add the key "Header Search Paths."
/usr/include/libxml2 -- This is the non-recurisve option
/usr/include/libxml2\** -- This is the recursive option and WILL
In XCode 5:
Add "${SDK_DIR}"/usr/include/libxml2 to your Header Search Paths
Add libxml2.dylib in Build Phases