15

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.

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

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

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?

tskulbru
  • 2,336
  • 1
  • 20
  • 38

2 Answers2

2

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

Steps: (from Apple)

  1. In the project editor, select the target to which you want to add a run script build phase.
  2. Click Build Phases at the top of the project editor.
  3. Choose Editor > Add Build Phase > Add Run Script Build Phase.
  4. Disclose the Run Script section in the project editor.
  5. Configure the script in the Run Script template.
Allen
  • 6,505
  • 16
  • 19
  • I've tried this without success.I need it to run before and after build. Since it has to change the watch storyboard before i start building the watch target, and then change it back after it has been built – tskulbru Feb 04 '16 at 08:49
  • @tskulbru the clean up you should do it after archive, put the cleanup command in the post-actions of Archive. – Allen Feb 04 '16 at 16:01
  • I tried to use post-action of build/archive etc from my main app build scheme to cleanup but for some reason it seemed like it wasnt late enough and the changes got included back into the watch app which then failed to install since it didnt have the correct changes. – tskulbru Feb 04 '16 at 16:27
  • @tskulbru you need put the clean up in post-action of archive, not build! the install happens after the build, and you need to stick with a process for code commit, then select new target, build, test & archive, select another target, build, test & archive. – Allen Feb 04 '16 at 21:17
  • Ok thanks! What if i need this to be run when I also test on the simulator/connected device, where should i put the cleanup then? archive build task is just for when exporting the ipa file right (when actually archiving)? – tskulbru Feb 05 '16 at 14:28
  • @tskulbru since you will clean up when archive, so it's does not matter you run test on simulator / device, as long as you don't select another target in the middle, you will be fine. – Allen Feb 05 '16 at 17:58
0

My solution is to go the Build settings of each watch extension target, setting the Product module name to the same value, for example, xxx_watch_extension. Then we should be able to choose this module for custom classes on the storyboard.

It works fine for me.

Jibeex
  • 5,509
  • 3
  • 27
  • 37