Capacitor plugin that assists with app updates. It supports retrieving app update information on Android and iOS and supports in-app updates on Android.
npm install @capawesome/capacitor-app-update
npx cap sync
This plugin will use the following project variables (defined in your app’s variables.gradle
file):
$androidPlayAppUpdateVersion
version ofcom.google.android.play:app-update
(default:2.1.0
)$androidPlayServicesBaseVersion
version ofcom.google.android.gms:play-services-base
(default:18.0.1
)
No configuration required for this plugin.
A working example can be found here: robingenz/capacitor-plugin-demo
import { AppUpdate } from '@capawesome/capacitor-app-update';
const getCurrentAppVersion = async () => {
const result = await AppUpdate.getAppUpdateInfo();
return result.currentVersion;
};
const getAvailableAppVersion = async () => {
const result = await AppUpdate.getAppUpdateInfo();
return result.availableVersion;
};
const openAppStore = async () => {
await AppUpdate.openAppStore();
};
const performImmediateUpdate = async () => {
const result = await AppUpdate.getAppUpdateInfo();
if (result.updateAvailability !== AppUpdateAvailability.UPDATE_AVAILABLE) {
return;
}
if (result.immediateUpdateAllowed) {
await AppUpdate.performImmediateUpdate();
}
};
const startFlexibleUpdate = async () => {
const result = await AppUpdate.getAppUpdateInfo();
if (result.updateAvailability !== AppUpdateAvailability.UPDATE_AVAILABLE) {
return;
}
if (result.flexibleUpdateAllowed) {
await AppUpdate.startFlexibleUpdate();
}
};
const completeFlexibleUpdate = async () => {
await AppUpdate.completeFlexibleUpdate();
};
getAppUpdateInfo(...)
openAppStore(...)
performImmediateUpdate()
startFlexibleUpdate()
completeFlexibleUpdate()
addListener('onFlexibleUpdateStateChange', ...)
removeAllListeners()
- Interfaces
- Enums
getAppUpdateInfo(options?: GetAppUpdateInfoOptions | undefined) => Promise<AppUpdateInfo>
Returns app update informations.
Only available on Android and iOS.
Param | Type |
---|---|
options |
GetAppUpdateInfoOptions |
Returns: Promise<AppUpdateInfo>
openAppStore(options?: OpenAppStoreOptions | undefined) => Promise<void>
Opens the app store entry of the app in the Play Store (Android) or App Store (iOS).
Only available on Android and iOS.
Param | Type |
---|---|
options |
OpenAppStoreOptions |
performImmediateUpdate() => Promise<AppUpdateResult>
Performs an immediate in-app update.
Only available on Android.
Returns: Promise<AppUpdateResult>
startFlexibleUpdate() => Promise<AppUpdateResult>
Starts a flexible in-app update.
Only available on Android.
Returns: Promise<AppUpdateResult>
completeFlexibleUpdate() => Promise<void>
Completes a flexible in-app update by restarting the app.
Only available on Android.
addListener(eventName: 'onFlexibleUpdateStateChange', listenerFunc: (state: FlexibleUpdateState) => void) => PluginListenerHandle
Adds a flexbile in-app update state change listener.
Only available on Android.
Param | Type |
---|---|
eventName |
'onFlexibleUpdateStateChange' |
listenerFunc |
(state: FlexibleUpdateState) => void |
Returns: PluginListenerHandle
removeAllListeners() => Promise<void>
Remove all listeners for this plugin.
Prop | Type | Description |
---|---|---|
currentVersion |
string |
Version code (Android) or CFBundleShortVersionString (iOS) of the currently installed app version. Only available on Android and iOS. |
availableVersion |
string |
Version code (Android) or CFBundleShortVersionString (iOS) of the update. Only available on Android and iOS. |
availableVersionReleaseDate |
string |
Release date of the update in ISO 8601 (UTC) format. Only available on iOS. |
updateAvailability |
AppUpdateAvailability |
The app update availability. Only available on Android and iOS. |
updatePriority |
number |
In-app update priority for this update, as defined by the developer in the Google Play Developer API. Only available on Android. |
immediateUpdateAllowed |
boolean |
true if an immediate update is allowed, otherwise false . Only available on Android. |
flexibleUpdateAllowed |
boolean |
true if a flexible update is allowed, otherwise false . Only available on Android. |
clientVersionStalenessDays |
number |
Number of days since the Google Play Store app on the user's device has learnt about an available update if an update is available or in progress. Only available on Android. |
installStatus |
FlexibleUpdateInstallStatus |
Flexible in-app update install status. Only available on Android. |
minimumOsVersion |
string |
The minimum version of the operating system required for the app to run in iOS. Only available on iOS. |
Prop | Type | Description |
---|---|---|
country |
string |
The two-letter country code for the store you want to search. See http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 for a list of ISO Country Codes. Only available on iOS. |
Prop | Type | Description |
---|---|---|
country |
string |
The two-letter country code for the store you want to search. See http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 for a list of ISO Country Codes. Only available on iOS. |
Prop | Type |
---|---|
code |
AppUpdateResultCode |
Prop | Type |
---|---|
remove |
() => Promise<void> |
Prop | Type | Description |
---|---|---|
installStatus |
FlexibleUpdateInstallStatus |
Flexible in-app update install status. |
bytesDownloaded |
number |
Returns the number of bytes downloaded so far. undefined if the install status is other than DOWNLOADING . |
totalBytesToDownload |
number |
Returns the total number of bytes to be downloaded for this update. undefined if the install status is other than DOWNLOADING . |
Members | Value |
---|---|
UNKNOWN |
0 |
UPDATE_NOT_AVAILABLE |
1 |
UPDATE_AVAILABLE |
2 |
UPDATE_IN_PROGRESS |
3 |
Members | Value |
---|---|
UNKNOWN |
0 |
PENDING |
1 |
DOWNLOADING |
2 |
INSTALLING |
3 |
INSTALLED |
4 |
FAILED |
5 |
CANCELED |
6 |
DOWNLOADED |
11 |
Members | Value | Description |
---|---|---|
OK |
0 |
The user has accepted the update. |
CANCELED |
1 |
The user has denied or cancelled the update. |
FAILED |
2 |
Some other error prevented either the user from providing consent or the update to proceed. |
NOT_AVAILABLE |
3 |
No update available. |
NOT_ALLOWED |
4 |
Update type not allowed. |
INFO_MISSING |
5 |
App update info missing. You must call getAppUpdateInfo() before requesting an update. |
The Android Developers documentation describes how to test in-app updates using internal app sharing: https://developer.android.com/guide/playcore/in-app-updates/test
See CHANGELOG.md.
See LICENSE.
This plugin is based on the Capacitor App Update plugin. Thanks to everyone who contributed to the project!