Enabling Hot Code Push to Mobile Applications


#1

Hello all,

I have been having a lot of trouble deciphering the documentation on how to enable hot code push (HCP) on my mobile app. After some flailing around I finally hit on a formula that works and I think I can explain how to properly enable this. I find the documentation to be tantalizingly close to describing how to do it, but I had a hard time putting it together.

Connections

What we are really configuring is the IP address that the client will attempt to connect to the server with for HCP and configuring the server so it properly listens on that communication channel and sends HCP updates when necessary.

For my example below, I am setting up my server to reside on my local lan with an address of http://192.168.1.100:3000

Mobile application configuration during development

I follow the instructions here. I connect my iPhone to my Mac and I run a command like below on a Mac to create my mobile application:

meteor run ios-device -p 3050 --mobile-server http://192.168.1.100:3000

Once the app is built and loaded I simply disconnect the iPhone from my mac and it is ready to connect to a server at port 3000. I also stop the server running at port 3050 by hitting ctrl-C. Now I have a mobile device with an app on it that is ready to connect to a server running at port 3000.

Let me describe what each part of the command line does:

  1. meteor run ios-device: build the mobile app then load it on a connected iPhone and also run a server. (note: this is not really the server that I want to connect the mobile app to, but it is necessary to create the app code).
  2. -p 3050: set my port for the server to be 3050. I do this because I do not really want to run this server. I am simply using the command to create the mobile app for my iPhone so I set the server port to be 3050 so that it will not collide with my real server at port 3000.
  3. --mobile-server http://192.168.1.100:3000: when building the mobile app set it up so that it looks to http://192.168.1.100:3000 as its server.

OK, now I have an iPhone with my app loaded. Next I have to start the server.

Starting the server

I run this command on a Mac:

env ROOT_URL=http://192.168.1.100:3000 meteor -p 3000 --mobile-server http://192.168.1.100:3000

This will run my server with HCP working on my mobile device. (I test it out by modifying my base HTML file adding some text and watch it update on the application, pretty cool!)

Let me describe what each part of this command does:

  1. env ROOT_URL=http://192.168.1.100:3000: this is really key. The way I think about it…, this makes the server refer to itself as http://192.168.1.100:3000 which will be key for enabling HCP. The docs describe it here.
  2. meteor -p 3000: this starts the server running on port 3000. Note: this is a little redundant, meteor defaults to port 3000. I added it for completeness.
  3. --mobile-server http://192.168.1.100:3000: I have no idea why this needs to be specified, but without it HCP does not work for me. I filed issue #7760 but have not really heard back whether this is a documentation issue a code issue or if I am doing something else wrong. If I left this option off, my app connects fine, but there is no HCP :disappointed:.

Great, now I have a server that can support HCP to my mobile applications!

How do I use this day to day?

Essentially, now I can make many changes to my application and the server will update automatically and then perform an HCP to my mobile app.

Occasionally, I need to update the app on the iPhone (e.g. if I add a package, subtract a package or upgrade my meteor version). When I do I can simply run the app update code while the server code is still running.

I can also set up my server to serve over the internet web pipes with my home ip address. I simply substitute my lan ip address for the ip address of my network connection. I use Comcast and have found that the ip address to my house is fairly static.

Hopefully, this can help someone that is as stuck as I was.


#2

Thanks Brucejo, :slight_smile: for such nice explanation.
I have a question, Do I need to build the mobile app every time. Whenever I make some changes or just push my changes to server app and HCP will update the mobile app?


#3

The objective of HCP is that it will update your mobile app without having to rebuild and install the new app. So no, you do not need to rebuild your app to see changes.

But there are caveats:

  • any changes to native code will require you to rebuild your app.
  • any additions or subtractions of cordova plugins will require a rebuild
  • any additions or subtractions of packages will require you to rebuild your app. (at one point I found this in some issue threads, but I cannot find it now)
  • any update of meteor will require you to rebuild your app.

Usually, when you make this sort of change the app will revert to the originally built version. So essentially when that happens go ahead and rebuild.