简体   繁体   中英

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)

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 = "com.apple.product-type.application.watchapp2";

Change this to:

productType = "com.apple.product-type.application"; OR productType = "com.apple.product-type.framework";

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 = "com.apple.product-type.application.watchapp2";

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM