问题
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)
回答1:
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!
来源:https://stackoverflow.com/questions/33000527/duplicating-target-for-watchos2-with-app-and-extension-on-xcode