Standalone framework - ios

I'm working on a project where I created a SDK (cocoapods) with two dependencies - AFNetworking and Realm.
Here is my process:
I create cocoapods project (in this project code is visible)
I use cocoapods-package to build a framework (with mangled symbols).
I then copy this framework to another cocoapods project which will be distributed to the public.
User who wants to use this SDK then 'installs' this cocoapod. When he does this AFNetworking and Realm are installed alongside (because they are dependencies)
What I would like to do is somehow embed AFNetworking and Realm inside a framework. I know that framework will be bigger in size. Main reason for doing this is so that user is not obligated to use the same version of AFNetworking and Realm.

The CocoaPods Packager is taking care of what you want here automatically.
You can pull in third-party dependencies using CocoaPods. (CocoaPods Packager is even capable of mangling symbols to improve compatibility with any symbols that might appear in the integrating app.)
The packager builds open-source podspecs for you. This podspec needs to declare all sources, resources and dependencies. Please note that podspecs never lint nor build when not all of their dependencies are declared correctly.
But as the packager takes care of vendoring the dependencies by mangling their symbols, it allows you to create a big binary, where the dependencies were included from static libraries.
On base of that build product, you can have a modified version of your podspec. This should not declare the dependencies anymore when they are included and shouldn't need declare the source files or need to have them publicly available anywhere, but instead you declare the built binary as vendored library. This still needs to specify the header files and have them accessible, so that consumers of the podspec are able to interface the API of your library.
The CocoaPods Packager creates this variant of the podspec for you as well.

Related

How to use the Framework with external dependency

I'm having the framework which has the external dependency with Alamofire. If I try to use the framework in my project, it showing ld: framework not found Alamofire in framework
I had setup all things to consume the framework in project.
Added framework in Embedded binaries and Build copy phase file
Things which I have tried: Check here
I need to use my framework with external pod dependencies.
Note: I have searched a lot and tried many solutions but know work in my case.
You may use a dependency manager like Carthage or CocoaPods in order to manage external dependencies in your framework. Follow their instructions how to use a framework from within a framework. This is the easy part.
Enable CocoaPods respectively Carthage in your framework so that it can be imported as external dependency by other projects. For CocoaPods this is more elaborated and requires you to create and publish a Podspec. Note, that you can create a private Pod if you don't want to share your framework. You will find more resources in the web (CocoaPods) how to accomplish all this. For Carthage usually there's little to no extra effort. Host your framework in some repository (private or public).
In your application, follow the instructions from the dependency manager how to import dependencies for an app. You possibly need to explicitly add secondary dependencies for Carthage (i.e. Alamofire) much like you add other depenendcies. CocoaPods would do this for your app project automatically when you install the Pods.
Import your framework in your sources. Before you build, ensure your dependencies will be build. Again, look for the documentation of the dependency manager how you accomplish this.

Is it possible to distribute binary ios framework using carthage

Please bear with me because I spent considerable amount of time on this. I am also relatively a beginner with swift and iOS.
What I did
- built a framework using cocoa touch
- clean, build and it succeeds without a problem.
- made the scheme shared
- did carthage build --no-skip-current
- did carthage archive
- copied only the zip file to a fresh new directory and uploaded with release in git.
- In a different project tried to pull the framework using carthage
and I get the error Dependency "xxx-ios" has no shared framework schemes then I copied the scheme directly and pushed it in the git along the zip. nothing. Tried without the zip together with the scheme. nothing.
Then I created a fresh framework and I did carthage build --no-skip-current and I uploaded the whole thing in the project folder to git. That pulls properly with carthage. Then I removed some part of that folder so that the scheme inside .xcodeproj and the carthage build folder remain, then I get a different error. At this point it got me thinking if carthage does support binary framework distribution.
In my company, they want it so that I don't expose the code - so I am trying to distribute built binary of the framework.
I would really appreciate any help or guides of what different things I could try to single out the problem. Thanks.
Edit
someone had almost exactly the same issue as mine in their issues here but a couple of conversations later it is closed without a solution.
It sounds like you're using a github dependency in your Cartfile and attaching a binary of your framework to the GitHub Release. But you don't have any code in the repository, so Carthage is complaining because it can't actually build it.
That's as designed—Carthage doesn't support distributing binary-only frameworks that way. Binaries attached to GitHub Releases are only meant as a way to speed up builds.
However, Carthage does have a mechanism for binary-only dependencies: binary dependencies.

CocoaPods not working on framework target

Im building a IOS app that uses a third-party library.
The library project is inherited from another developer that im unable to ask anything.
It is configured to use CocoaPods to manage dependencies, it has a lot of them.
When i run "pod install" it downloads all of them and creates the workspace.
In the workspace i have set the app target as dependent from the framework project product
Then i try to build it and it says it cannot find one of the dependencies of the framework project (it is on the podfile)
Then i found the framework project is missing "[CP] Embed Pods Frameworks" in build phases (the app project has it)
Also the "Pods_[targetName].framework" is shown in red (even when it indeed is in the build products folder, the path is correct)
I found this issue that seems to be exactly my problem but im unable to see if it has been fixed or not and what could i do to workaround this.
Same effect for me, my issue was the s.source_files in the podspec did not reference a location with actual files after a refactor.

iOS : How to generate a .framework file from a GitHub project

There is a Swift project on GitHub that I want to include in my iOS app.
In my iOS app, I use Carthage. But the GitHub project is not compatible with Carthage (only with Cocoapods), so I need to include the .framework file in my project manually.
How can I generate the .framework file without Carthage?
Building the framework is not always the same across projects. That being said, there should be a target available when you open the project to make the framework build. It should look something like this.
After clicking run the framework is usually output to the products directory.
If this doesn't work for you with this project then maybe you could share a link to the github page for the project and I could provide more instruction.
Fork Project
Change scheme to shared in scheme management (more information on Carthage docs)
Add your fork to your Cartfile
You can stop here but I highly recommend do this after:
Update README with information about Carthage support
Make a pull request

React Native using Cocoapods

Is it possible to use cocoapods when using React Native?
If so, How can I require in JavaScript the pods projects?
Thanks in advance!
Yes. It's possible. React Native project is pretty much normal iOS application (In terms of XCode required to build it and quite a lot of React Native internal code is well... Native Obj-C). Since React Native project is already run via xcworkspace, so it's perfectly possible to add Obj-C pods to the ReactNative project.
Since a lot of dependencies used by RN apps are pure javascript rather than Obj-C code, it's more than convenient to keep both dependency systems - Cocoapods (for Obj-C dependencies) and npm (for javascript). Pods are kept in "Pods" directory and npm under "node-modules" and they are not clashing with each other. And it's pretty convenient actually to have different types of dependencies run by different dependency management systems.
UPDATE: by default ReactNative project is .xcodeproj based, but it's easy to convert it to .xcodeworkspace.
I even tried to add React Native itself as Cocoapods dependency and it was sort of working (but some dependencies expected React in the "node-modules" dir so I abandoned it).

Resources