简体   繁体   English

Apple Watch,多个目标和共享Watchkit Extension / Watckit应用程序目标

[英]Apple Watch, several targets and shared Watchkit Extension / Watckit app targets

I am currently working on projects that has a lot (10+) targets. 我目前正在研究有很多(10+)目标的项目。 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). 这是一个白色品牌的应用程序,每个目标专用于客户,所有目标共享完全相同的代码,但编译不同的资源(特别是.xcsassets)。

I would like to integrate Apple Watch to my project, simply to enable notifications on the watch as well. 我想将Apple Watch集成到我的项目中,只是为了在手表上启用通知。 It requires to add 2 targets, Watchkit Extension and App. 它需要添加2个目标,Watchkit Extension和App。 (nota : the WatchKit App target will be linked to the same .xcassets than the associated iPhone App to inherit the AppIcon). (注意:WatchKit App目标将链接到相同的.xcassets,而不是相关的iPhone App来继承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. 在我的subversion文件夹中创建了很多新文件,.plist,并使目标列表非常庞大。

Would it be possible to share those 2 additional targets to all my customers? 是否可以向所有客户分享这2个额外目标? 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 ? 也许通过使用脚本使WatchKit应用程序/扩展目标自动匹配(更新目标名称,包ID等)可能会构建方案/ iOs目标?

Any idea would be more than welcome. 任何想法都会受到欢迎。

You can control the watch dependent target plist using configurations and user defined settings to control the bundle id. 您可以使用配置和用户定义的设置来控制依赖于监视的目标plist来控制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. 假设您有10个目标,并且您需要创建监视应用程序,然后将每个主应用程序的软件包ID定义到项目设置下的用户设置(不是特定于目标),这允许您将该名称与两个监视目标一起扩展到目标。

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). 例如,对于目标A,您将捆绑ID定义为BUNDLE_A_ID as com.company.a您可以将$(BUNDLE_A_ID)作为捆绑ID用于app目标, $(BUNDLE_A_ID).watchapp or $(BUNDLE_A_ID).watchappextension到您的监视目标中您不需要在每个目标中定义捆绑ID,您对这些设置的定义将与一个地方(项目设置)捆绑在一起。

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. 我假设您正在使用iOS应用程序和Apple手表应用程序,您需要添加更多Apple手表应用程序而无需重复代码。

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 第1步:文件/新建/目标选择“WatchOS”选项卡,然后选择“WatchKit应用程序”选择要与此新Apple Watch应用程序链接的应用程序单击下一步

Step 2: Look at the new folders created for your new Apple Watch app and delete all the *.swift and *.storyboard 第2步:查看为新Apple Watch应用程序创建的新文件夹,并删除所有* .swift和* .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. 第3步:选择最初工作的拳头Apple Watch应用程序的.storyboard和.swift文件,您应该为它们分配新的和旧的目标成员资格。 In the future, all your watch app files should have those targets selected. 将来,您的所有观看应用文件都应该选择这些目标。

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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