Patching Mobile Apps in Tabris.js

July 29, 2015 | 3 min Read

Imagine you’ve just published a new version of your app when you discover a critical bug that will render the app unusable for half of your user base. The fix may be simple, but rolling out another version takes some time for app store review and users to install the update. With Tabris.js, you can now deploy hotfixes to your users immediately, without having to wait for an update.

How does this work? Tabris.js 1.1 provides a feature to download and install a patch from a URL. A patch is just a zip archive of files that overlay files in your application. Since Tabris.js applications are written in JavaScript, it’s easy to replace a single file with a fixed version.

To make use of this feature, an app must detect an available patch, download and install it, and eventually reload itself. The detection is up to you. You can use push notifications, poll a REST service, or whatever you wish. Once the app discovered that a patch is available, it must download and install it. This is done by a single method call (installPatch). When the installation was successful, the app can reload itself at any point to make the patch effective. Here’s a simple example:

tabris.app.installPatch(patchUrl, function(error, patch) {
  if (error) {
    // TODO: show error dialog
  } else {
    // TODO: show confirmation dialog
    tabris.app.reload();
  }
});

However, in most cases a manual reload of the application will be preferred, to make sure your update does not interrupt the users or make it look like the app has crashed.

But doesn’t Apple prevent downloading executable code? Turns out that it’s not entirely forbidden. The iOS Developer Program Agreement (PDF) (Section 3.3.2) contains the following paragraph:

An Application may not download or install executable code. Interpreted code may only be used in an Application if all scripts, code and interpreters are packaged in the Application and not downloaded. The only exception to the foregoing is scripts and code downloaded and run by Apple’s built-in WebKit framework or JavascriptCore, provided that such scripts and code do not change the primary purpose of the Application by providing features or functionality that are inconsistent with the intended and advertised purpose of the Application as submitted to the App Store.

Tabris.js scripts are executed in the built-in JavascriptCore engine, so as long as the downloaded scripts do not change the primary purpose of the Application, you should be fine.

The patch feature is convenient not only for minor app updates but also for enterprise distribution, where it will make it possible to roll out changes with minimal disruption to the users.

The patch feature is available in Tabris.js 1.1, which is available as of today.

Ralf Sternberg

Ralf Sternberg

Ralf is a software engineer with a history as Eclipse committer and project lead.

In recent years, he devoted himself to JavaScript technologies and helped pulling off …