Apple Watch 预构建操作以更改故事板 customModule 引用 [英] Apple Watch pre-build action to change storyboard customModule references

查看:20
本文介绍了Apple Watch 预构建操作以更改故事板 customModule 引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有一个项目,其中包含同一个应用程序的 3 个不同版本(不同的品牌等),效果很好.从那以后,我添加了 3 个新的 Apple Watch 目标(每个应用版本"1 个),其中 2 个引用了主"Apple Watch 目标中的文件.

I currently have a project with 3 different versions of the same app (different branding and such), which is working just fine. I've since then added 3 new Apple Watch targets (1 for each app "version"), where which 2 of them reference the files in the "master" Apple Watch target.

只要我记得更改每个情节提要视图的模块引用,以便它映射到相应 watchkit 扩展目标中的正确接口控制器,一切都可以正常工作.

Everything works fine as long as i remember to change the module reference for each storyboard view, so that it maps to the correct interface controller in the corresponding watchkit extension target.

但是,每次我需要运行/构建应用程序版本/目标时都要记住切换它是一种痛苦,而不是真正的长期解决方案.

However, remembering to switch this every time i need to run/build a app version/target is a pain and not really a long term solution.

我创建了以下命令,我希望在正确的时间运行该命令,以便在编译之前更改情节提要引用.

I've created the following command which I want to be run at the correct time, such that it changes the storyboard references before it is compiled.

perl -pi.bak -e 's/customModule=\"(.*?)\">/customModule=\"watchMyTarget_Extension\">/g' ${SRCROOT}/watch/Base.lproj/Interface.storyboard

我还得出结论,我可能希望在编译应用程序后重置更改,因为我不想让 git 抱怨文件更改.这就是上述脚本创建 .bak 文件的原因.所以在编译完成并在设备上打包/运行后,我想运行

I also concluded that I would probably want to reset the change after the app was compiled, since I don't want to have a file change for git to complain about. Which is why the aforementioned script creates a .bak file. So after the compilation is done and packed/run on device or whatever, I want to run

mv ${SRCROOT}/watch/Base.lproj/Interface.storyboard.bak ${SRCROOT}/watch/Base.lproj/Interface.storyboard

我已经尝试将脚本放在目标的(watchTarget,而不是 appTarget)构建方案中,Build->Pre/Post Actions 似乎没有任何效果.我尝试将它放在 Run->Pre/Post Actions 中,这在一定程度上起作用了,但似乎在将应用程序推送到模拟器之前启动了 post 操作,从而使应用程序崩溃(无法运行,查看设备日志"或类似内容).

I've tried placing the scripts in the target's (watchTarget, not appTarget) build scheme, Build->Pre/Post Actions which didn't seem to have any effect. And I tried putting it in Run->Pre/Post Actions which worked to some degree, but it seemed like the post action kicked in before the app was pushed to the simulator and thus crashing the application ("could not run see device logs" or something like that).

那么我到底需要将这些脚本放在哪里才能让它们在构建过程中的正确时间运行?

So where on earth do I need to put these scripts to have them run at the correct time in the build process?

推荐答案

you should use add New Run Script Phase in your target's Build Phases, 把它放在 Compile Sources 之前

you should use add New Run Script Phase in your target's Build Phases, place it before the Compile Sources

步骤:(来自 Apple)

  1. 在项目编辑器中,选择要添加运行脚本构建阶段.
  2. 点击项目编辑器顶部的构建阶段.
  3. 选择编辑器 > 添加构建阶段 > 添加运行脚本构建阶段.
  4. 在项目编辑器中公开运行脚本部分.
  5. 在运行脚本模板中配置脚本.

这篇关于Apple Watch 预构建操作以更改故事板 customModule 引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆