Skip to content

How to restrict Capacitor Live Updates to Native Versions

Live Updates are a powerful feature that allows you to deliver updates to your Capacitor app in real-time without having to resubmit your app to the app stores. However, it is important to make sure that only Binary Compatible Changes are delivered to your users to prevent incompatible updates. In this guide, you will learn how to restrict live updates to specific native versions.

Introduction

The Capawesome Cloud offers two different ways to restrict live updates to specific native versions:

  1. Versioned Builds
  2. Versioned Channels

Let's take a closer look at both options.

Versioned Builds

Versioned builds allow you to restrict live updates to specific native versions by defining a range of version codes for each platform.

Version Code

The version code (named versionCode on Android and CFBundleVersion on iOS) is the internal version number of your app. It is used to determine whether one version is more recent than another and must be incremented each time you release a new version of your app.

To create a versioned build, you only need to specify the minimum and maximum version codes for each platform:

  • Minimum: The native binary must have at least this version code to be compatible with the bundle.
  • Maximum: The native binary must have at most this version code to be compatible with the bundle.

For this, you can use the following Capawesome CLI command:

npx capawesome apps:bundles:create --android-min 10 --android-max 12 --ios-min 10 --ios-max 12

Versioned Channels

Versioned channels allow you to restrict live updates to specific native versions by defining a channel for each version code.

Channel

A Channel allows you to distribute different versions of your app to different groups of users.

To create a versioned channel, you can use the following Capawesome CLI command:

npx capawesome apps:channels:create --name production-10

In this example, we created a channel named production-10 for the version code 10.

To upload a bundle to a specific channel, you can use the following Capawesome CLI command:

npx capawesome apps:bundles:create --channel production-10

Finally, we need to set the correct channel in the app to ensure that only compatible bundles are downloaded:

import { LiveUpdate } from '@capawesome/capacitor-live-update';

const sync = async () => {
  // Get the version code of the native app
  const { versionCode } = await LiveUpdate.getVersionCode();
  // Select the channel based on the version code
  await LiveUpdate.setChannel({ channel: `production-${versionCode}` }); 
  // Automatically download and set the latest compatible bundle
  await LiveUpdate.sync();
};

Conclusion

By following the steps in this guide, you can ensure that only compatible updates are delivered to your users and prevent any issues caused by incompatible changes. While Versioned Builds seems to be the more straightforward approach, Versioned Channels are the recommended way to restrict live updates to specific native versions because they are easier to manage and therefore less error-prone.

If you have any questions, just create a discussion in the GitHub repository. Make sure you follow Capawesome on X so you don't miss any future updates.