Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apple Watch pre-build action to change storyboard customModule references

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?

like image 652
tskulbru Avatar asked Jan 27 '16 13:01

tskulbru


1 Answers

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.
like image 87
Allen Avatar answered Oct 26 '22 02:10

Allen