insanoid insanoid - 1 year ago 92
iOS Question

Duplicating target for WatchOS2 with App and Extension on Xcode

I have a project with a WatchOS2 target along with an Extension. I want to duplicate both the WatchOS App target and the extension. However, when I duplicate the WatchOS App target it is still linked to the old extension. Since we no longer have access to build phases for WatchOS App I cannot change it in the Embed App Extension Phase.

Inital State

  • WatchAppTarget1 (Embed Extension - WatchAppExtension1)

  • WatchAppExtension1

Final State

  • WatchAppTarget1 (Embed Extension - WatchAppExtension1)

  • WatchAppExtension1

  • WatchAppTarget-Duplicate (Embed Extension still pointing to - WatchAppExtension1)

  • WatchAppExtension-Duplicate

Is there anyway of changing the WatchOS App Target to accept the duplicated Extension as its choice to embed (other than manually editing the .pbxproj)

Answer Source

For now least irritating way I found to achieve this after wasting lots of hours is by changing the WatchOS app to behave like a framework so Xcode provides the Build phases section.

Open the project.pbxproj in a text editor, go to the section which goes like/* Begin PBXNativeTarget section */ find your WatchOS target (the one you want to change) in the configuration, it should have a line :

productType = "";

Change this to:

productType = ""; OR productType = "";

Now open the project in Xcode you should be apple to see the Build Phases section, go there and remove the old extension references in "Target Dependencies" and "Embed App Extension" and replace it with the new ones. Once you are done go back to the project.pbxproj and undo your change and make the WatchOS target back to productType = "";

Sometimes you might have to make a fresh build scheme for both the WatchOS and the iOS app, but this should do the trick!