Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Podfile with iOS and OSX Support

Tags:

I'm trying to setup CocoaPods with a legacy project which has both iOS and a OSX targets.

If, at the top of my Podfile, I specify:

platform :osx, '10.9' 

and, as an example, specify a pod like CorePlot:

pod 'CorePlot' 

Then, after a pod update, I see Mac specific sources in my Pods directory:

Pods/CorePlot/framework/MacOnly 

which is okay, except that if I were to specify :ios as the platform then I see:

Pods/CorePlot/framework/iPhoneOnly 

and I do not see the MacOnly directory.

CorePlot's podspec specifies these directories based on the platform, which is why they are showing up differently based on the platform I select. However, I would like to be able to have my Podfile work for my iOS and OSX targets.

I continued and thought perhaps I could specify the platform based on the target in my project, and omit the top level platform declaration:

target "OSX" do   platform :osx, '10.9' end  target "iOS" do   platform :ios, '7.0' end 

However, once I again do a pod update now I get a version compatibility error:

[!] The platform of the target Pods (OS X ) is not compatible with CorePlot (1.5.1) which has a minimum requirement of iOS 3.1.3 - OS X 10.5."

Which would seem to indicate that CocoaPods is not recognizing the version information in my target block.

And, if I add a platform to the top level, in addition to the target specific platform, I then get only the code for whichever platform the top level platform indicated.

Am I forced to have two separate projects? One for iOS and one for Mac OS X, or is there a way to do this?

Many thanks,

Levi

   CocoaPods : 0.31.1         Ruby : ruby 2.0.0p247 (2013-06-27 revision 41674) [universal.x86_64-darwin13]     RubyGems : 2.0.3         Host : Mac OS X 10.9.2 (13C64)        Xcode : 5.1.1 (5B1008) Ruby lib dir : /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib Repositories : master - https://github.com/CocoaPods/Specs.git @ bf6ff4b23c2e8b9e5fe5840eddfc3bad122eb932 
like image 716
levigroker Avatar asked Apr 11 '14 21:04

levigroker


People also ask

What is iOS Podfile?

The Podfile is a specification that describes the dependencies of the targets of one or more Xcode projects. The file should simply be named Podfile . All the examples in the guides are based on CocoaPods version 1.0 and onwards.

Why we use CocoaPods in iOS?

CocoaPods manages library dependencies for your Xcode projects. The dependencies for your projects are specified in a single text file called a Podfile. CocoaPods will resolve dependencies between libraries, fetch the resulting source code, then link it together in an Xcode workspace to build your project.


2 Answers

Based on https://github.com/CocoaPods/CocoaPods/issues/2043#issuecomment-59295308

def import_pods     pod 'CorePlot' end  target :ios do     platform :ios, '7.0'     import_pods end  target :osx do     platform :osx, '10.9'     import_pods end 
like image 190
Eric Avatar answered Oct 26 '22 12:10

Eric


You could use abstract_targets to separate pods by platform:

use_frameworks!  # Common pods pod ...  abstract_target 'Mobile' do      platform :ios, '13.0'      # Common pods for mobile   pod ...      target 'My iOS App' do          # Target specific pods     pod ...        end    end  abstract_target 'Mac' do      platform :osx, '11.0'    # Common Mac pods   pod ...      target 'My Mac App' do    # Target specific pods        end    end 
like image 30
Rivera Avatar answered Oct 26 '22 13:10

Rivera