Keep the watch app away from Release Build

In recent time, My colleague and I have developed a WatchOS App prototype. Then Our boss wanted to merge that POC to the production branch. That means the end users will have a chance to uncover our POC. That shouldn’t happen.

WatchOS app is an extension, it doesn’t stand alone. It basically needs a host app. The WatchOS project usually is a sub-project which eventually its product will be attached to the main app. But XCode doesn’t give us an option to keep the extension out for Release Build. (The release build is the build which will be submitting it to App Store, and reaches out to end users)

Can we do the proccess differently? OK, I’m going to write a tutorial to handle this situation.

Start

First of all, I create a new iOS app project and add an additional target for the WatchOS app. It will look like this

This slideshow requires JavaScript.

I’m going to explain a bit.

  • We see 3 targets on the left-hand side (MyApp is the host app which will attach the WatchApp inside of it)
  • In the project’s build phases, We see 2 sections marked with stars
    • Section 1 – Target dependencies: This section basically triggers building the WatchApp target.
    • Section 2 – Embed Watch Content: This is created by XCode automatically when creating the WatchApp target. What this section will do is embed the WatchApp into MyApp. This is the way We publish the WatchOS App. When building the project, We will find the app which includes the watch folder.

how-it-publish-the-watchos-app

Because We don’t have much control with this section. We can’t customize it like ask it to embed the watch app for DEBUG build only, so We need to remove this section and handle by ourself.

delete_embeded_watchapp_section

Shell Scripting

This slideshow requires JavaScript.

And then We need a little bit of magic. I have prepared a script to fill out. Please take a look at the script below.

We need some more steps

It is not done yet, We need some more steps:

  • On the top-left corner, click on + icon to add new “copy files phrase”.
  • We must place the “Copy Files” phase ahead of the script section
  • Set the destination to “Absolute Path”, the “Path” value will be $(TARGET_BUILD_DIR)
  • Add the file which we need to copy. Click + icon at the bottom to add, then choose “WatchApp.app”

This slideshow requires JavaScript.

Done

Ok, everything is in place, Press the shortcut CMD + R to build the iOS app. You would find the message hk >>> Attach WatchApp.app successfully”

attach-watch-app-successfully1.png

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s