1.3.1 • Published 2 years ago

@robingenz/capacitor-app-update v1.3.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

🚧 This project is currently under active development and has not yet been sufficiently tested. It might be changed in backward-incompatible ways.

This plugin supports retrieving app update information on Android and iOS.
Additionally, this plugin supports in-app updates on Android.

Maintainers

MaintainerGitHubSocial
Robin Genzrobingenz@robin_genz

Installation

npm install @robingenz/capacitor-app-update
npx cap sync

Android Variables

This plugin will use the following project variables (defined in your app’s variables.gradle file):

  • $androidPlayCore version of com.google.android.play:core (default: 1.9.0)

Configuration

No configuration required for this plugin.

Usage

import { AppUpdate } from '@robingenz/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();
};

API

getAppUpdateInfo()

getAppUpdateInfo() => Promise<AppUpdateInfo>

Returns app update informations.

Only available for Android and iOS.

Returns: Promise<AppUpdateInfo>


openAppStore()

openAppStore() => Promise<void>

Opens the app store entry of the app in the Play Store (Android) or App Store (iOS).

Only available for Android and iOS.


performImmediateUpdate()

performImmediateUpdate() => Promise<AppUpdateResult>

Performs an immediate in-app update.

Only available for Android.

Returns: Promise<AppUpdateResult>


startFlexibleUpdate()

startFlexibleUpdate() => Promise<AppUpdateResult>

Starts a flexible in-app update.

Only available for Android.

Returns: Promise<AppUpdateResult>


completeFlexibleUpdate()

completeFlexibleUpdate() => Promise<void>

Completes a flexible in-app update by restarting the app.

Only available for Android.


addListener('onFlexibleUpdateStateChange', ...)

addListener(eventName: 'onFlexibleUpdateStateChange', listenerFunc: (state: FlexibleUpdateState) => void) => PluginListenerHandle

Adds a flexbile in-app update state change listener.

ParamType
eventName'onFlexibleUpdateStateChange'
listenerFunc(state: FlexibleUpdateState) => void

Returns: PluginListenerHandle


Interfaces

AppUpdateInfo

PropTypeDescription
currentVersionstringVersion code (Android) or CFBundleShortVersionString (iOS) of the currently installed app version. Only available for Android and iOS.
availableVersionstringVersion code (Android) or CFBundleShortVersionString (iOS) of the update. Only available for Android and iOS.
availableVersionReleaseDatestringRelease date of the update in ISO 8601 (UTC) format. Only available for iOS.
updateAvailabilityAppUpdateAvailabilityThe app update availability. Only available for Android and iOS.
updatePrioritynumberIn-app update priority for this update, as defined by the developer in the Google Play Developer API. Only available for Android.
immediateUpdateAllowedbooleantrue if an immediate update is allowed, otherwise false. Only available for Android.
flexibleUpdateAllowedbooleantrue if a flexible update is allowed, otherwise false. Only available for Android.

AppUpdateResult

PropType
codeAppUpdateResultCode

PluginListenerHandle

PropType
remove() => Promise<void>

FlexibleUpdateState

PropTypeDescription
installStatusFlexibleUpdateInstallStatusFlexible in-app update install status.
bytesDownloadednumberReturns the number of bytes downloaded so far. undefined if the install status is other than DOWNLOADING.
totalBytesToDownloadnumberReturns the total number of bytes to be downloaded for this update. undefined if the install status is other than DOWNLOADING.

Enums

AppUpdateAvailability

MembersValue
UNKNOWN0
UPDATE_NOT_AVAILABLE1
UPDATE_AVAILABLE2
UPDATE_IN_PROGRESS3

AppUpdateResultCode

MembersValueDescription
OK0The user has accepted the update.
CANCELED1The user has denied or cancelled the update.
FAILED2Some other error prevented either the user from providing consent or the update to proceed.
NOT_AVAILABLE3No update available.
NOT_ALLOWED4Update type not allowed.
INFO_MISSING5App update info missing. You must call getAppUpdateInfo() before requesting an update.

FlexibleUpdateInstallStatus

MembersValue
UNKNOWN0
PENDING1
DOWNLOADING2
INSTALLING3
INSTALLED4
FAILED5
CANCELED6
DOWNLOADED11

Test with internal app-sharing

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

Changelog

See CHANGELOG.md.

License

See LICENSE.