Exclude pod depends on platform in podfile - ios

I need to exclude a pod from my podfile depends on the platform. I don't want to add another target, my podfile needs have only 1 target.
Here an example:
target 'single_target' do
#if platform is iOS
pod 'PodForIOS'
#if platform is OSX
pod 'PodForOSX'
end
My issue: How can I specify which pods belongs to which platform ?
Thanks

Finnaly I've found a solution
In the podfile:
target 'single_target' do
pod 'PodForIOS'
pod 'PodForOSX'
end
In the .podspec:
# Speficy platforms
s.platform = :ios, :osx
s.ios.deployment_target = '6.0'
s.osx.deployment_target = '10.8'
# Set dependency
s.ios.dependency 'PodForIOS'
s.osx.dependency 'PodForOSX'

A target in a Podfile refers to a target in an .xcproject. And those are strictly tied to a specific plateform:
So you should go with one abstract target (in Podfile) and multiple targets (in Project).

Related

Remove pod dependency based on platform

I'm adding an apple watch extension to my project and I'd like to use the same pods I'm using for my main iOS app. However, the podspec I'm using for my iOS app has a dependency that causes an error when I include the watch extension as a target in my podfile. Is there a way to remove dependencies based on platform (ios, watchos)?
The error:
[!] The platform of the target `My Watch Extension` (watchOS 5.2) is not compatible with `Library X (10.1.19)`, which does not support `watchos`.
So far I'm doing the following in my podfile:
target 'My Watch Extension' do
platform :watchos, '5.2'
pod 'MyPod', :path => 'MyPod'
end
And I added the following to my podspec:
s.platforms = { :ios => "10.0", :watchos => "5.2"}
Is it possible to have to separate podspecs?
You can set different dependencies for different platforms
spec.dependency 'Alamofire'
spec.ios.dependency 'Crashlytics'
Here is a simplified version of my podfile. I just include different pod's for the different targets.
def external_dependencies
pod 'Alamofire'
pod 'SQLite.swift/SQLCipher'
end
def caller_id_external_dependencies
pod 'GMCPagingScrollView'
pod 'KeychainAccess'
end
target 'Goob' do
external_dependencies
internal_dependencies
target 'UnitTests' do
pod 'Firebase/Core'
pod 'Firebase/Messaging'
pod 'SQLite.swift/SQLCipher'
inherit! :search_paths
end
end
target 'GoobCallerId' do
caller_id_external_dependencies
end

Cocoapod can't identify my target after it was renamed

I had been using cocoapods to pod stuff but after I've renamed my whole xcode project, the cocoapod doesn't reconise my renamed target when I am trying to pod lottie, and I don't know how to replace the target with the new one
This error showed in terminal
[!] Unable to find a target named `Infinity Math`, did find `Infinity Math.temp_caseinsensitive_rename`, `Infinity Math.temp_caseinsensitive_renameTests`, and `Infinity Math.temp_caseinsensitive_renameUITests`.
My Pod file
platform :ios, '12.0'
target 'Infinity Math' do
use_frameworks!
pod 'UITextField+Shake', '~> 1.2'
pod 'SPAlert'
pod 'CBFlashyTabBarController'
pod 'Spring', :git => 'https://github.com/MengTo/Spring.git'
pod 'lottie-ios'
target 'InfinityMathTests' do
inherit! :search_paths
end
target 'InfinityMathUITests' do
inherit! :search_paths
end
end
What should I do next in order to pod new pods?
Give the targets in the Podfile the same names that show up in Xcode:
target 'Infinity Math' do
target 'Infinity MathTests' do
target 'Infinity MathUITests' do
I've fixed it by renaming the target to the ones in the error
InfinityMath.temp_caseinsensitive_rename,
InfinityMath.temp_caseinsensitive_renameTests, InfinityMath.temp_caseinsensitive_renameUITests
It's weird

How can I replace link_with with target blocks?

I have updated cocoapods today to 1.0.0 version. I got this string when I update the pods:
[!] InvalidPodfilefile: [!] The specification oflink_within the Podfile is now unsupported, please use target blocks instead..
The content of my Pod file is
# Uncomment this line to define a global platform for your project
# platform :ios, '9.0'
target 'QuickStart' do
# Uncomment this line if you're using Swift or would like to use dynamic frameworks
# use_frameworks!
# Pods for QuickStart
source 'https://github.com/CocoaPods/Specs.git'
link_with ['QuickStart']
xcodeproj 'QuickStart'
pod 'ADALiOS', :git => 'https://github.com/AzureAD/azure-activedirectory-library-for-objc.git', :branch=> 'convergence'
pod 'NXOAuth2Client'
source 'https://github.com/CocoaPods/Specs.git'
link_with ['QuickStart']
xcodeproj 'QuickStart'
pod 'ADALiOS'
end

Meaning of each Cocoapods build target

What is the purpose of each target in a Cocoapods workspace?
When I created a new CocoaPods library via "pod lib create Foo", I expected only two targets: One to build my library, and one to build my example.
But the resulting xcworkspace has a total of four targets:
Project Foo
Target Foo_Tests
Project Pods
Target Pods-Foo_Tests
Target Pods-Foo_Tests-Foo
Target Pods-Foo_Tests-Foo-Foo
What's the meaning of these targets?
(I chose no demo application, view-based testing, or testing frameworks.)
There are 2 project in your workspace one is yours and the other is cocoapods, and cocoapods adds new target for each pod which you add in your Podfile. For example, let's say this is your Podfile :
platform :ios, '7.0'
pod 'AFNetworking', '~> 2.5.4'
pod 'BPXLUUIDHandler'
you should see in your pod project's target list something like this :
but what is that mean?
Targets where cocoapods manage everything for each pod. For example if you choose AFNwtworking target in pod project, you must see something like this :
but for example how cocoapods know to add "Link binary with libraries" frameworks like above? Well, please check AFNetworking's podspec file for this :
s.public_header_files = 'AFNetworking/*.h'
s.source_files = 'AFNetworking/AFNetworking.h'
s.subspec 'Serialization' do |ss|
ss.source_files = 'AFNetworking/AFURL{Request,Response}Serialization.{h,m}'
ss.ios.frameworks = 'MobileCoreServices', 'CoreGraphics'
ss.osx.frameworks = 'CoreServices'
end
s.subspec 'Security' do |ss|
ss.source_files = 'AFNetworking/AFSecurityPolicy.{h,m}'
ss.frameworks = 'Security'
end
s.subspec 'Reachability' do |ss|
ss.source_files = 'AFNetworking/AFNetworkReachabilityManager.{h,m}'
ss.frameworks = 'SystemConfiguration'
end
as you can see above this lines "ss.ios.frameworks" are describe what is going on there.
Hope everything is clear now.

Why does Cocoapods adds HockeyMac-SDK to my iOS Target?

Given that Podfile
workspace 'Foo'
target :Foo_Mac do
xcodeproj 'Mac/Foo_Mac'
platform :osx
pod 'HockeySDK-Mac'
end
target :Foo_iOS do
xcodeproj 'Foo_iOS'
platform :ios, '7.0'
pod 'Parse-iOS-SDK'
end
How comes both my Pods-Foo_iOS.xcconfig & Pods-Foo_Mac.xcconfig contains
HEADER_SEARCH_PATHS = "${PODS_ROOT}/Headers/HockeySDK-Mac" "${PODS_ROOT}/Headers/Parse-iOS-SDK"
Shouldn't it just have the ones from the Podfile?
You’re absolutely right, that’s a bug. Please file a ticket.

Resources