7

I have an iOS project with a lot of pods, around twenty. I want to integrate a watchOS 2 app in, but CocoaPods requires that the podspec contain support for watchOS (as seen here: http://blog.cocoapods.org/CocoaPods-0.38/)

At first, I thought I could fork all of the pods that aren't updated, point my podfile to those forked repos, and bob's your uncle. The problem is that some of the pods that I'm using are closed/not-public. Is there a way for me to not build the main application's pods for the watchOS target? Like using target isolation like so?:

target "Watch" do end

I can't seem to get that ^ potential solution to build, as it still tries to build the pods. I've also tried this repo, no luck: https://github.com/orta/cocoapods-expert-difficulty

Cœur
  • 37,241
  • 25
  • 195
  • 267
Zach Lucas
  • 1,631
  • 5
  • 15
  • 29

2 Answers2

15

There are two way to integrate pods using podfile with WathOS.

1) Add Required pods directly to watch extension as below.

target '<your watch Extension Name>' do

platform :watchos, '2.0'
pod 'RealmSwift'
pod 'Alamofire'
pod 'MMWormhole', '~> 2.0.0'

end 

2) Create Shared pods and add to both watch extension and iOS target both.

def sharedPods
    pod 'RealmSwift'
    pod 'Alamofire'
end

target '<your watch Extension Name>' do
platform :watchos, '2.0'
   sharedPods
end


target '<your iOSApp Name>' do
platform :ios, '8.0'
   sharedPods
end

Add only watchOS and iOS supported pods in sharedPods, Do not add pods in sharedPods which does not support watchOS. e.g.

def sharedPods
        pod 'RealmSwift'
        pod 'Alamofire'
        pod 'otherWatchOS&iOS supported Pod1'
        pod 'otherWatchOS&iOS supported Pod2'
    end

Add only iOS supported pods in target '<your iOSApp Name>' e.g.

target '<your iOSApp Name>' do
platform :ios, '8.0'
   sharedPods
   pod 'otherOnlyiOS supported Pod1'
   pod 'otherOnlyiOS supported Pod2'
end

So, this way you can add required pods for required targets.

Hitendra Solanki
  • 4,871
  • 2
  • 22
  • 29
  • That's what I've tried. The problem I'm talking about is that many of the pods that I am using don't support watchOS in their pod spec. So if I use them in either of the ways you described, cocoa pods throws an error saying that the pods don't support watchOS. Is there any way to build the main app with all of the pods, but build the watchOS target with no pods? – Zach Lucas Dec 29 '15 at 13:56
  • please check edited answer as per your requirements. – Hitendra Solanki Dec 30 '15 at 05:18
1

I've found my problem! I was using Swift for my Watch code, but my parent app is in Obj-c. Thought it wouldn't be a problem except the watch target attempts to compile the Swift bridging header that I use in my main app, which is what was leading to those pods building unnecessarily. So, the solution is either specify a different bridging header for your Watch target or using Obj-c!

Zach Lucas
  • 1,631
  • 5
  • 15
  • 29