Skip to content

Plugin methods V3

API

download(…)

download(options: { url: string; }) => Promise<{ version: string; }>

Download a new version from the provided URL, it should be a zip file, with files inside or with a unique folder inside with all your files

ParamType
options{ url: string; }

Returns: Promise<{ version: string; }>


set(…)

set(options: { version: string; versionName?: string; }) => Promise<void>

Set version as current version, set will return an error if there are is no index.html file inside the version folder. versionName is optional, and it’s a custom value that will be saved for you.

ParamType
options{ version: string; versionName?: string; }

getId()

getId() => Promise<{ id: string; }>

Get unique ID used to identify device into auto-update server

Returns: Promise<{ id: string; }>


delete(…)

delete(options: { version: string; }) => Promise<void>

Delete version in storage

ParamType
options{ version: string; }

list()

list() => Promise<{ versions: string[]; }>

Get all available versions

Returns: Promise<{ versions: string[]; }>


reset(…)

reset(options?: { toAutoUpdate?: boolean | undefined; } | undefined) => Promise<void>

Set the builtin version (the one sent to Apple Store / Google Play Store ) as the current version

ParamType
options{ toAutoUpdate?: boolean; }

current()

current() => Promise<{ current: string; currentNative: string; }>

Get the current version, if none is set it returns builtin, currentNative is the original version install on the device

Returns: Promise<{ current: string; currentNative: string; }>


reload()

reload() => Promise<void>

Reload the view


versionName()

versionName() => Promise<{ versionName: string; }>

Get the version name, if it was set during the set phase

Returns: Promise<{ versionName: string; }>


notifyAppReady()

notifyAppReady() => Promise<void>

Notify native plugin that the update is working, only in auto-update


delayUpdate()

delayUpdate() => Promise<void>

Skip updates in the next time the app goes into the background, only in auto-update


cancelDelay()

cancelDelay() => Promise<void>

allow update in the next time the app goes into the background, only in auto-update

Events

Listen to download events

import { CapacitorUpdater } from '@capgo/capacitor-updater';
CapacitorUpdater.addListener('download', (info: any) => {
console.log('download was fired', info.percent);
});

On iOS, Apple doesn’t allow you to show a message when the app is updated, so you can’t show a progress bar.

Angular specific

You need to use ngZone to let the event be detected in angular

public updatingDownloadProgress: number = 0;
constructor(
...
private ngZone: NgZone
...) {
CapacitorUpdater.addListener("download", (state: DownloadEvent) => {
this.ngZone.run(() => {
this.updatingDownloadProgress = state.percent;
});
});
}

addListener(‘download’, …)

addListener(eventName: 'download', listenerFunc: DownloadChangeListener) => Promise<PluginListenerHandle> & PluginListenerHandle

Listen for download event in the App, let you know when the download is started, loading and finished

ParamType
eventName'download'
listenerFuncDownloadChangeListener

Returns: Promise<PluginListenerHandle> & PluginListenerHandle

Since: 2.0.11


addListener(‘majorAvailable’, …)

addListener(eventName: 'majorAvailable', listenerFunc: MajorAvailableListener) => Promise<PluginListenerHandle> & PluginListenerHandle

Listen for Major update events in the App, let you know when a major update is blocked by setting disableAutoUpdateBreaking

ParamType
eventName'majorAvailable'
listenerFuncMajorAvailableListener

Returns: Promise<PluginListenerHandle> & PluginListenerHandle

Since: 2.3.0


addListener(‘updateAvailable’, …)

addListener(eventName: 'updateAvailable', listenerFunc: UpdateAvailableListener) => Promise<PluginListenerHandle> & PluginListenerHandle

Listen for update event in the App, and let you know when the update update is ready to install at the next app start

ParamType
eventName'updateAvailable'
listenerFuncUpdateAvailableListener

Returns: Promise<PluginListenerHandle> & PluginListenerHandle

Since: 2.3.0


addListener(string, …)

addListener(eventName: string, listenerFunc: (...args: any[]) => any) => Promise<PluginListenerHandle>
ParamType
eventNamestring
listenerFunc(...args: any[]) => any

Returns: Promise<PluginListenerHandle>


removeAllListeners()

removeAllListeners() => Promise<void>

Interfaces

PluginListenerHandle

PropType
remove() => Promise<void>

DownloadEvent

PropTypeDescriptionSince
percentnumberCurrent status of download, between 0 and 100.2.0.11

MajorAvailableEvent

PropTypeDescriptionSince
versionstringEmit when a new major version is available.2.3.0

UpdateAvailableEvent

PropTypeDescriptionSince
versionstringEmit when a new update is available.3.0.0

Type Aliases

DownloadChangeListener

(state: DownloadEvent): void

MajorAvailableListener

(state: MajorAvailableEvent): void

UpdateAvailableListener

(state: UpdateAvailableEvent): void

Settings

After install capacitor-updater to your project, you can configure some behavior:

  • resetWhenUpdate set it false to disable the reset version when updating
  • autoUpdateUrl the target URL to get updates
  • autoUpdate true or false depend on if you want manual or auto
  • statsUrl the target URL for stats, set it to "" to disable stats
{
"appId": "**.***.**",
"appName": "Name",
"plugins": {
"CapacitorUpdater": {
"resetWhenUpdate": false
}
}
}