Xcode Cocoapods Not Finding Framework Header Files - ios

So I am working on an old Xcode project that was developed by a separate developer and am having build errors when running on my Mac due to Cocoapods. The first error is "The sandbox is not in sync with the Podfile.lock”, which I can fix by removing the various Cocoapods files and the old xcworkspace from the project and running pod install in the terminal to create all of this again. The new issue is that some of the classes cannot find the header files from the podfile's listed frameworks.
My theory is because this is an old project and the old developer didn't put version caps on some of the frameworks in the podfile, is that the project is trying to use old methods / classes that are deprecated in the newest updated frameworks. However I am not sure how to get around this as I tried putting version caps on those frameworks in the podfile without any success.

There are two paths:
You investigate each framework, estimate the approximate pod version that could have been used at the time project was active, and use particular version of each pod (you can find info on configuring pod version here
This solution won't work in 90% of cases, however, as iOS is evolving really fast and old frameworks are most probably outdated and not compatible with latest changes.
You investigate each framework and understand what actually changed. You look at headers that each pod has, understand what actually changed and implement changes in your code.
You start with headers, making sure that you include the right ones, and then start migrating code to the newest versions.
Big projects usually have migration guides.
There are no other options. As soon as any project becomes dependant on external code, it's up to developers to ensure that it's up-to-date.

Related

How to migrate manually added iOS thirdpart sdk to pod version

We have two years old iOS app that needs to update recently.
There is an old SDK (2.0) that manually added to project. Now this SDK have 4.0 version on cocoapods and we really like to move this SDK to pod.
What is the best way to do it? just delete the library from Build Phase and pod install?
Changing the old code to support new SDK is not problem for me.
just delete the library from Build Phase and pod install?
Yes this would be the easiest way to go about it.
Also make sure you remove it from your local files inside the project so that Xcode cannot get confused, make sure you remove all remains of the pod (except the code ofcourse).

Xcode 11.1 Error: Multiple commands produce

I see that there are several other questions regarding this problem.
Like: Xcode 10 Error: Multiple commands produce
I am asking this a new because it is for Xcode 11.1 and not older version and I think that the other questions have too many responses and people easily can get lost in them. Here we can try to answer using newer information with quicker access.
After update to Xcode 11.1 and update of cocoa pods ( no pods were actually updated, only the pods project was regenerated ).
I started to get the following error with FBSDK:
Multiple commands produce '/Users/myUser/Library/Developer/Xcode/DerivedData/myProject-euqkymjpeftprkgkcjyqpnkbalbr/Build/Products/Debug-iphoneos/FBSDKCoreKit-iOS/FBSDKCoreKit.framework/PrivateHeaders/FBSDKRestrictiveDataFilterManager.h':
1) Target 'FBSDKCoreKit-iOS' (project 'Pods') has copy command from '/Users/myUser/Documents/Workspace/myProjectDir/Pods/FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit/AppEvents/Internal/FBSDKRestrictiveDataFilterManager.h' to '/Users/myUser/Library/Developer/Xcode/DerivedData/myProject-euqkymjpeftprkgkcjyqpnkbalbr/Build/Products/Debug-iphoneos/FBSDKCoreKit-iOS/FBSDKCoreKit.framework/PrivateHeaders/FBSDKRestrictiveDataFilterManager.h'
2) Target 'FBSDKCoreKit-iOS' (project 'Pods') has copy command from '/Users/myUser/Documents/Workspace/myProjectDir/Pods/FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit/AppEvents/Internal/RestrictiveDataFilter/FBSDKRestrictiveDataFilterManager.h' to '/Users/myUser/Library/Developer/Xcode/DerivedData/myProject-euqkymjpeftprkgkcjyqpnkbalbr/Build/Products/Debug-iphoneos/FBSDKCoreKit-iOS/FBSDKCoreKit.framework/PrivateHeaders/FBSDKRestrictiveDataFilterManager.h'
I let you know my case. It was related to a Cocoapod Library installed.
The normal steps to install a Cocoapod is, after running the pod install, then you use to go at your "import library section" in your project, then add it.
I removed the library from there, and the problem disappeared instantaneouslly.
Anyway, to use the library still you need to import it as always in your files.
import YourLibrary
class your {
}
Shows the place where the library must be removed from.
In my case the problem was the that those files :
FBSDKRestrictiveDataFilterManager.h
FBSDKRestrictiveDataFilterManager.m
were added twice in the FBSDKCoreKit-iOS project. I deleted the older ones ( by comparing the actual SDK code from GitHub ). I don't know who is to blame Cocoa Pods or Facebook, but if you get that error or some kind of similar one regarding the same file, I suggest that you check for file duplicates.

Embedding frameworks inside closed-source Swift framework

Our company wants to distribute a closed-source SDK for iOS to our clients. I've been using Cocoapods to build the framework and built an example app making use of it. Previously the app worked fine on the simulator as well as when deployed on the device. However, I was also embedding the Pods.framework file in the app itself. One other piece of information that may be of interest is that the framework is written in Swift, the included cocoapods dependencies are both Swift and Objective-C.
I wanted to make the pods requirements easier to manage so the user doesn't need to be concerned with them and tried to embed the Pods.framework file inside of the SDK we're building - so I removed the steps to Embed Pods Frameworks and Copy Pods Resources from the example app, leaving them only in the framework, I also removed Pods.framework as a dependency of the example app, leaving it only in the SDK. This seemed to work in the simulator, but the app now crashes on mobile device with dyld: Library not loaded error.
Upon researching it, I stumbled into a few related discussions:
https://github.com/CocoaPods/CocoaPods/issues/344 https://objectpartners.com/2014/06/25/developing-private-in-house-libraries-with-cocoapods/
However, the suggested solution of using private pods does not look like it would work for us, it's my understanding that the source code in the private pod would still be open, and we can't share it with our clients.
Could someone advise on a solution that would work in this case?
OK, I finally have a more durable solution. It's a modified, cleaner version of my old one now that I understand how Xcode links in my Swift sub-frameworks better
Problem that makes distribution/compilation a bit ugly:
Since Swift standard libraries aren't bundled on the device like Obj-C, nor are they guaranteed to be stable between versions yet (stable binary interface promised in Swift 3: https://github.com/apple/swift-evolution#development-major-version--swift-30) we have to make sure the entire project is compiled against the same version of Swift. That means the guy using your closed-source framework has to be using the same version of Swift in their Xcode for their project as you did for compiling the library, even if he's not using Swift in his code because ultimately it's his version of Swift that gets bundled into the app and your SDK runs against. This is only an issue for closed-source frameworks because open-source ones will always be compiled against the same version as final project. Possible workaround is to restrict clients to same version you use or distribute multiple compilations (i.e. Swift 2.1 and Swift 2.0). To remedy this, you could provide users with copies of binaries compiled against multiple versions of Swift.
Aside from that, here is what I had to do during compilation/distribution to make a binary framework that works in Swift:
When building the framework:
In project target, make sure to add Pods.framework to Linked Frameworks and Libraries (make sure this is a pre-compiled RED version of Pods.framework, I had a black compiled Pods.framework in the same directory which built fine but then resulted in a framework that would cause the project to complain about missing armv7 architecture during linker phase in later project)
In Build Settings, under User-Defined section, add a field called BITCODE_GENERATION_MODE and set it to bitcode
DO NOT #import any frameworks in your bridging header, all instructions telling you to do that are leftover from Swift 1.0-1.2 days, you don't need it anymore and it does more harm than good (the later project will complain that it can't find these headers that aren't even exposed to it)
Change build target to Generic iOS Device, Archive and Export the framework
When building the project using the framework:
Drag and drop the framework into the project, in General tab add it to Embedded Binaries and Linked Frameworks and Libraries (you only need to add the framework itself, not the sub-frameworks or the pods file)
In Build Settings tab, add a new path to Framework Search Paths: $(PROJECT_DIR)/MyFramework.framework/Frameworks
Build the project

Podfile usage for iOS apps

I'm very new to using podfiles and have a bit of confusion around how they work and what I need to do to use them. I have followed the 'Getting Started' section on the main website and have successfully created a podfile and run install to pull in the dependencies. The questions I have are as follows:
I see a new section in my project which appears to list the pods i've requested, however they all seem to be in red - is that normal? If not what have I done wrong / what do I need to do?
In terms of some of the Core iOS frameworks (e.g. UIKit, Foundation, etc.) do I still need to manually import them as frameworks into my project? Can I add them to my podfile so I can manage everything in a single place? If so how (does the syntax vary/differ?)?
They appear as red because this frameworks not built yet. After you build project they should look normal.
Yes, CocoaPods only handle third-party dependencies.

iOS - update a framework

I built an app that uses a third party SDK. Recently I had to update the SDK with a new version. I removed the framework files from my application folder, copied the new ones, added them to the project, but it seems XCode is caching the old version.
I tried Clean, tried to delete Derived Data, nothing works. At this point it seems the only available option is to recreate the project and import all the source files. Obviously I am not keen on that. There must be an easy, fast solution to this issue.
Any clue?
Cocoa pods are easy to use and install.
CocoaPods is the dependency manager for Objective-C projects. It has
thousands of libraries and can help you scale your projects elegantly.
Ultimately, its goal is to improve discoverability of, and engagement
in, third party open-source libraries, by creating a more centralized
ecosystem.
However the frameworks need to be compatible with cocoa pods which most libraries are. You use terminal to install. This site may give you an idea how to install it.
Fixed it. I deleted all copies of the old SDK, whether or not they were in my project folder. Seems like XCode was linking to one of them... Another mystery.

Resources