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.
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
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
Let me describe what each part of the command line does:
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).
-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
3050so that it will not collide with my real server at port
--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:3000as 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:
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:3000which will be key for enabling HCP. The docs describe it here.
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.
--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 .
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.