Skip to main content

Capacitor SDK Reference

The Live Updates API offers programmatic access to the Live Updates SDK and the most control over the user experience.

Within your Capacitor app project, install the Live Updates SDK:

npm install @capacitor/live-updates
npx cap sync

With the Live Updates SDK installed, add a "LiveUpdates" configuration section under plugins in capacitor.config.ts (or capacitor.config.json) file. Set autoUpdateMethod to none to use the SDK API:

import { CapacitorConfig } from '@capacitor/cli';

const config: CapacitorConfig = {
plugins: {
LiveUpdates: {
appId: '042a1261',
channel: 'Production',
autoUpdateMethod: 'none',
maxVersions: 3
}
}
};

export default config;

Sync

  • sync(): void
  • Description: Check for and download a new live update if available.
  • Returns: Promise<SyncResult>. A response describing a live update if one is available.

SyncResult Interface

  • activeApplicationPathChanged: boolean - true if a new live update has just been downloaded
  • liveUpdate.appId: string - Appflow App Id
  • liveUpdate.channel: string - Live Update channel name that the update has been deployed to
  • snapshot.buildId: string - Appflow Build Id
  • snapshot.id: string - Internal Appflow Id
  • source: string - download if a new live update has just been downloaded or cache if a cached live update has been found instead
const result = await LiveUpdates.sync();

Reload

  • reload(): void
  • Description: Reload the app. A new version will be shown afterward if available.
  • Returns: Promise<void>. Nothing.
import * as LiveUpdates from '@capacitor/live-updates';

// Check for new live update
const result = await LiveUpdates.sync();
// If active path has changed, then a new live update was downloaded
if (result.activeApplicationPathChanged) {
// Reload the app; the new version will appear afterward
await LiveUpdates.reload();
}

Get and Set Config

  • setConfig(): LiveUpdateConfig
  • Description: Change Live Updates configuration during runtime. Only the values provided will change. Changes are persisted between app launches, except for when a new binary is shipped. In that case, the persisted config is wiped and the config shipped with the application is used.
  • Returns: Promise<void>. Nothing.

If you can set it, you can get it!

  • getConfig(): void
  • Description: Retrieve current config settings.
  • Returns: Promise<LiveUpdateConfig>
let currentConfig = await LiveUpdates.getConfig();
console.log(currentConfig.channel); // production
console.log(currentConfig.appId); // 123

await LiveUpdates.setConfig({
channel: "staging",
appId: "456"
});

currentConfig = await LiveUpdates.getConfig();
console.log(currentConfig.channel); // staging
console.log(currentConfig.appId); // 456

Reset Config

  • resetConfig(): void
  • Description: Wipes the persisted config and uses the one shipped with the application.
  • Return: Promise<void>. Nothing.
await LiveUpdates.resetConfig();

Examples

For more API usage examples, see Live Update Strategies.