Apple Watch, several targets and shared Watchkit Extension / Watckit app targets
Asked Answered
S

2

7

I am currently working on projects that has a lot (10+) targets. This is a white branded app, each target is dedicated to a customer, all targets share the exact same code but compile different resources (.xcsassets notably).

I would like to integrate Apple Watch to my project, simply to enable notifications on the watch as well. It requires to add 2 targets, Watchkit Extension and App. (nota : the WatchKit App target will be linked to the same .xcassets than the associated iPhone App to inherit the AppIcon).

While it's ok for a project with only a few targets, this is really not practical in my case. A lot of new files created, .plist across my subversion folders, and make the list of targets really huge.

Would it be possible to share those 2 additional targets to all my customers? Maybe is it possible by using scripts to make the WatchKit App/Extension targets match (updating target name, bundle id, etc) automatically the scheme/iOs target to be built ?

Any idea would be more than welcome.

Stott answered 6/5, 2015 at 20:29 Comment(3)
Duplicate Target for watch kit 1 extension and watch kit 1 app along with watch os 2 targets. Now just Change the bundle identifier for all the new targets. Plus you will not change add the new targets in to the relevant app manually. Let me know if you don't understand, I will create a tutorial.Hess
Did you get this working? Im trying just the same thing but there seems to be a lingering bundleid somewhere (cant find it with search even)Lotti
I have a similar question. AFAIK, Xcode is not even giving me an option to select an extension to buildLoach
V
0

You can control the watch dependent target plist using configurations and user defined settings to control the bundle id. Suppose you have 10 target and you need to create watch app then define the bundle id for each main app into user setting under project setting (not specific to target), which allow you to extend that name to your target along with two watch target.

For example for target A, you defined bundle id as BUNDLE_A_ID as com.company.a you can use $(BUNDLE_A_ID) as bundle id into app target, $(BUNDLE_A_ID).watchapp or $(BUNDLE_A_ID).watchappextension into your watch targets so you don't need to define bundle id in each targets, your definition of these setting will tied up with one place (project setting).

Vanmeter answered 20/5, 2015 at 20:38 Comment(0)
H
0

CAUTION: Make a copy of your project or create a new branch to try this solution.

I found how to fix it. I'm assuming you have an iOS app working and an Apple watch app working and you need to add more Apple watch apps without repeating code.

Step 1: File/New/Target Select the "WatchOS" tab and then select "WatchKit App" Select the app you wanna link with this new Apple Watch app Click Next

Step 2: Look at the new folders created for your new Apple Watch app and delete all the *.swift and *.storyboard

Step 3: Select the .storyboard and .swift files of your fist Apple Watch app that was working originally and you should assign them the new and the old Target Membership. In the future, all your watch app files should have those targets selected.

enter image description here

Hectoliter answered 17/4, 2017 at 20:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.