Update Ionic Capacitor apps without App/Play Store review (Code-push / hot-code updates).
You have 3 ways possible :
Join the discord to get help.
I maintain a more user-friendly and complete documentation here.
Plugin version | Capacitor compatibility | Maintained |
---|---|---|
v6.*.* | v6.*.* | ✅ |
v5.*.* | v5.*.* | Critical bug only |
v4.*.* | v4.*.* | ⚠️ Deprecated |
v3.*.* | v3.*.* | ⚠️ Deprecated |
> 7 | v4.*.* | ⚠️ Deprecated, our CI got crazy and bumped too much version |
Add the NSPrivacyAccessedAPICategoryUserDefaults
dictionary key to your Privacy Manifest (usually ios/App/PrivacyInfo.xcprivacy
):
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSPrivacyAccessedAPITypes</key>
<array>
<!-- Add this dict entry to the array if the file already exists. -->
<dict>
<key>NSPrivacyAccessedAPIType</key>
<string>NSPrivacyAccessedAPICategoryUserDefaults</string>
<key>NSPrivacyAccessedAPITypeReasons</key>
<array>
<string>CA92.1</string>
</array>
</dict>
</array>
</dict>
</plist>
We recommend to declare CA92.1
as the reason for accessing the UserDefaults
API.
npm install @capgo/capacitor-updater
npx cap sync
Create your account in capgo.app and get your API key
npx @capgo/cli@latest init API_KEY
And follow the steps by step to setup your app.For detailed instructions on the auto-update setup, refer to the Auto update documentation.
Download update distribution zipfiles from a custom URL. Manually control the entire update process.
capacitor.config.json
like below, set autoUpdate
to false.
// capacitor.config.json
{
"appId": "**.***.**",
"appName": "Name",
"plugins": {
"CapacitorUpdater": {
"autoUpdate": false,
}
}
}
import { CapacitorUpdater } from '@capgo/capacitor-updater'
CapacitorUpdater.notifyAppReady()
This informs Capacitor Updater that the current update bundle has loaded succesfully. Failing to call this method will cause your application to be rolled back to the previously successful version (or built-in bundle).
const version = await CapacitorUpdater.download({
url: 'https://github.com/Cap-go/demo-app/releases/download/0.0.4/dist.zip',
})
await CapacitorUpdater.set(version); // sets the new version, and reloads the app
Example: Using App-state to control updates, with SplashScreen: You might also consider performing auto-update when application state changes, and using the Splash Screen to improve user experience.
import { CapacitorUpdater, VersionInfo } from '@capgo/capacitor-updater'
import { SplashScreen } from '@capacitor/splash-screen'
import { App } from '@capacitor/app'
let version: VersionInfo;
App.addListener('appStateChange', async (state) => {
if (state.isActive) {
// Ensure download occurs while the app is active, or download may fail
version = await CapacitorUpdater.download({
url: 'https://github.com/Cap-go/demo-app/releases/download/0.0.4/dist.zip',
})
}
if (!state.isActive && version) {
// Activate the update when the application is sent to background
SplashScreen.show()
try {
await CapacitorUpdater.set(version);
// At this point, the new version should be active, and will need to hide the splash screen
} catch () {
SplashScreen.hide() // Hide the splash screen again if something went wrong
}
}
})
TIP: If you prefer a secure and automated way to update your app, you can use [capgo.app](https://capgo.app) - a full-featured, auto-update system.
### Store Guideline Compliance
Android Google Play and iOS App Store have corresponding guidelines that have rules you should be aware of before integrating the Capacitor-updater solution within your application.
#### Google play
Third paragraph of [Device and Network Abuse](https://support.google.com/googleplay/android-developer/answer/9888379?hl=en) topic describe that updating source code by any method besides Google Play's update mechanism is restricted. But this restriction does not apply to updating JavaScript bundles.
> This restriction does not apply to code that runs in a virtual machine and has limited access to Android APIs (such as JavaScript in a web view or browser).
That fully allow Capacitor-updater as it updates just JS bundles and can't update native code part.
#### App Store
Paragraph **3.3.2**, since back in 2015's [Apple Developer Program License Agreement](https://developer.apple.com/programs/ios/information/) fully allowed performing over-the-air updates of JavaScript and assets.
And in its latest version (20170605) [downloadable here](https://developer.apple.com/terms/) this ruling is even broader:
> Interpreted code may be downloaded to an Application, but only so long as such code:
- (a) does not change the primary purpose of the Application by providing features or functionality that are inconsistent with the intended and advertised purpose of the Application as submitted to the App Store
- (b) does not create a store or storefront for other code or applications
- (c) does not bypass signing, sandbox, or other security features of the OS.
Capacitor-updater allows you to respect these rules in full compliance, so long as the update you push does not significantly deviate your product from its original App Store approved intent.
To further remain in compliance with Apple's guidelines, we suggest that App Store-distributed apps don't enable the `Force update` scenario, since in the [App Store Review Guidelines](https://developer.apple.com/app-store/review/guidelines/) it is written that:
> Apps must not force users to rate the app, review the app, download other apps, or other similar actions to access functionality, content, or use of the app.
This is not a problem for the default behavior of background update, since it won't force the user to apply the new version until the next app close, but at least you should be aware of that ruling if you decide to show it.
### Packaging `dist.zip` update bundles
Capacitor Updater works by unzipping a compiled app bundle to the native device filesystem. Whatever you choose to name the file you upload/download from your release/update server URL (via either manual or automatic updating), this `.zip` bundle must meet the following requirements:
- The zip file should contain the full contents of your production Capacitor build output folder, usually `{project directory}/dist/` or `{project directory}/www/`. This is where `index.html` will be located, and it should also contain all bundled JavaScript, CSS, and web resources necessary for your app to run.
- Do not password encrypt the bundle zip file, or it will fail to unpack.
- Make sure the bundle does not contain any extra hidden files or folders, or it may fail to unpack.
## Updater Plugin Config
<docgen-config>
<!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
CapacitorUpdater can be configured with these options:
| Prop | Type | Description | Default | Since |
| ------------------------ | -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------ | ------- |
| **`appReadyTimeout`** | <code>number</code> | Configure the number of milliseconds the native plugin should wait before considering an update 'failed'. Only available for Android and iOS. | <code>10000 // (10 seconds)</code> | |
| **`responseTimeout`** | <code>number</code> | Configure the number of milliseconds the native plugin should wait before considering API timeout. Only available for Android and iOS. | <code>20 // (20 second)</code> | |
| **`autoDeleteFailed`** | <code>boolean</code> | Configure whether the plugin should use automatically delete failed bundles. Only available for Android and iOS. | <code>true</code> | |
| **`autoDeletePrevious`** | <code>boolean</code> | Configure whether the plugin should use automatically delete previous bundles after a successful update. Only available for Android and iOS. | <code>true</code> | |
| **`autoUpdate`** | <code>boolean</code> | Configure whether the plugin should use Auto Update via an update server. Only available for Android and iOS. | <code>true</code> | |
| **`resetWhenUpdate`** | <code>boolean</code> | Automatically delete previous downloaded bundles when a newer native app bundle is installed to the device. Only available for Android and iOS. | <code>true</code> | |
| **`updateUrl`** | <code>string</code> | Configure the URL / endpoint to which update checks are sent. Only available for Android and iOS. | <code>https://api.capgo.app/updates</code> | |
| **`statsUrl`** | <code>string</code> | Configure the URL / endpoint to which update statistics are sent. Only available for Android and iOS. Set to "" to disable stats reporting. | <code>https://api.capgo.app/stats</code> | |
| **`privateKey`** | <code>string</code> | Configure the private key for end to end live update encryption. Only available for Android and iOS. | <code>undefined</code> | |
| **`version`** | <code>string</code> | Configure the current version of the app. This will be used for the first update request. If not set, the plugin will get the version from the native code. Only available for Android and iOS. | <code>undefined</code> | 4.17.48 |
| **`directUpdate`** | <code>boolean</code> | Make the plugin direct install the update when the app what just updated/installed. Only for autoUpdate mode. Only available for Android and iOS. | <code>undefined</code> | 5.1.0 |
| **`periodCheckDelay`** | <code>number</code> | Configure the delay period for period update check. the unit is in seconds. Only available for Android and iOS. Cannot be less than 600 seconds (10 minutes). | <code>600 // (10 minutes)</code> | |
| **`localS3`** | <code>boolean</code> | Configure the CLI to use a local server for testing or self-hosted update server. | <code>undefined</code> | 4.17.48 |
| **`localHost`** | <code>string</code> | Configure the CLI to use a local server for testing or self-hosted update server. | <code>undefined</code> | 4.17.48 |
| **`localWebHost`** | <code>string</code> | Configure the CLI to use a local server for testing or self-hosted update server. | <code>undefined</code> | 4.17.48 |
| **`localSupa`** | <code>string</code> | Configure the CLI to use a local server for testing or self-hosted update server. | <code>undefined</code> | 4.17.48 |
| **`localSupaAnon`** | <code>string</code> | Configure the CLI to use a local server for testing. | <code>undefined</code> | 4.17.48 |
| **`allowModifyUrl`** | <code>boolean</code> | Allow the plugin to modify the updateUrl, statsUrl and channelUrl dynamically from the JavaScript side. | <code>false</code> | 5.4.0 |
| **`defaultChannel`** | <code>string</code> | Set the default channel for the app in the config. | <code>undefined</code> | 5.5.0 |
### Examples
In `capacitor.config.json`:
```json
{
"plugins": {
"CapacitorUpdater": {
"appReadyTimeout": 1000 // (1 second),
"responseTimeout": 10 // (10 second),
"autoDeleteFailed": false,
"autoDeletePrevious": false,
"autoUpdate": false,
"resetWhenUpdate": false,
"updateUrl": https://example.com/api/auto_update,
"statsUrl": https://example.com/api/stats,
"privateKey": undefined,
"version": undefined,
"directUpdate": undefined,
"periodCheckDelay": undefined,
"localS3": undefined,
"localHost": undefined,
"localWebHost": undefined,
"localSupa": undefined,
"localSupaAnon": undefined,
"allowModifyUrl": undefined,
"defaultChannel": undefined
}
}
}
In capacitor.config.ts
:
/// <reference types="@capgo/capacitor-updater" />
import { CapacitorConfig } from '@capacitor/cli';
const config: CapacitorConfig = {
plugins: {
CapacitorUpdater: {
appReadyTimeout: 1000 // (1 second),
responseTimeout: 10 // (10 second),
autoDeleteFailed: false,
autoDeletePrevious: false,
autoUpdate: false,
resetWhenUpdate: false,
updateUrl: https://example.com/api/auto_update,
statsUrl: https://example.com/api/stats,
privateKey: undefined,
version: undefined,
directUpdate: undefined,
periodCheckDelay: undefined,
localS3: undefined,
localHost: undefined,
localWebHost: undefined,
localSupa: undefined,
localSupaAnon: undefined,
allowModifyUrl: undefined,
defaultChannel: undefined,
},
},
};
export default config;
Promise<AppReadyResult>
--------------------
### setUpdateUrl(...)
```typescript
setUpdateUrl(options: UpdateUrl) => PromiseUpdateUrl
| contains the URL to use for checking for updates. |
**Since:** 5.4.0
--------------------
### setStatsUrl(...)
```typescript
setStatsUrl(options: StatsUrl) => PromiseStatsUrl
| contains the URL to use for sending statistics. |
**Since:** 5.4.0
--------------------
### setChannelUrl(...)
```typescript
setChannelUrl(options: ChannelUrl) => PromiseChannelUrl
| contains the URL to use for setting the channel. |
**Since:** 5.4.0
--------------------
### download(...)
```typescript
download(options: DownloadOptions) => PromiseDownloadOptions
| The {@link DownloadOptions} for downloading a new bundle zip. |
**Returns:** Promise<BundleInfo>
--------------------
### next(...)
```typescript
next(options: BundleId) => PromiseBundleId
| Contains the ID of the next Bundle to set on next app launch. {@link BundleInfo.id} |
**Returns:** Promise<BundleInfo>
--------------------
### set(...)
```typescript
set(options: BundleId) => PromiseBundleId
| A {@link BundleId} object containing the new bundle id to set as current. |
--------------------
### delete(...)
```typescript
delete(options: BundleId) => PromiseBundleId
| A {@link BundleId} object containing the ID of a bundle to delete (note, this is the bundle id, NOT the version name) |
--------------------
### list()
```typescript
list() => PromisePromise<BundleListResult>
--------------------
### reset(...)
```typescript
reset(options?: ResetOptions | undefined) => PromiseResetOptions
| Containing {@link ResetOptions.toLastSuccessful}, `true` resets to the builtin bundle and `false` will reset to the last successfully loaded bundle. |
--------------------
### current()
```typescript
current() => PromisePromise<CurrentBundleResult>
--------------------
### reload()
```typescript
reload() => PromiseMultiDelayConditions
| Containing the {@link MultiDelayConditions} array of conditions to set |
**Since:** 4.3.0
--------------------
### cancelDelay()
```typescript
cancelDelay() => PromisePromise<LatestVersion>
**Since:** 4.0.0
--------------------
### setChannel(...)
```typescript
setChannel(options: SetChannelOptions) => PromiseSetChannelOptions
| Is the {@link SetChannelOptions} channel to set |
**Returns:** Promise<ChannelRes>
**Since:** 4.7.0
--------------------
### unsetChannel(...)
```typescript
unsetChannel(options: UnsetChannelOptions) => PromiseUnsetChannelOptions
|
**Since:** 4.7.0
--------------------
### getChannel()
```typescript
getChannel() => PromisePromise<GetChannelRes>
**Since:** 4.8.0
--------------------
### setCustomId(...)
```typescript
setCustomId(options: SetCustomIdOptions) => PromiseSetCustomIdOptions
| is the {@link SetCustomIdOptions} customId to set |
**Since:** 4.9.0
--------------------
### getBuiltinVersion()
```typescript
getBuiltinVersion() => PromisePromise<BuiltinVersion>
**Since:** 5.2.0
--------------------
### getDeviceId()
```typescript
getDeviceId() => PromisePromise<DeviceId>
--------------------
### getPluginVersion()
```typescript
getPluginVersion() => PromisePromise<PluginVersion>
--------------------
### isAutoUpdateEnabled()
```typescript
isAutoUpdateEnabled() => PromisePromise<AutoUpdateEnabled>
--------------------
### removeAllListeners()
```typescript
removeAllListeners() => Promise'download'
|
| **`listenerFunc`** | (state: DownloadEvent) => void
|
**Returns:** Promise<PluginListenerHandle>
**Since:** 2.0.11
--------------------
### addListener('noNeedUpdate', ...)
```typescript
addListener(eventName: "noNeedUpdate", listenerFunc: (state: NoNeedEvent) => void) => Promise'noNeedUpdate'
|
| **`listenerFunc`** | (state: NoNeedEvent) => void
|
**Returns:** Promise<PluginListenerHandle>
**Since:** 4.0.0
--------------------
### addListener('updateAvailable', ...)
```typescript
addListener(eventName: "updateAvailable", listenerFunc: (state: UpdateAvailableEvent) => void) => Promise'updateAvailable'
|
| **`listenerFunc`** | (state: UpdateAvailableEvent) => void
|
**Returns:** Promise<PluginListenerHandle>
**Since:** 4.0.0
--------------------
### addListener('downloadComplete', ...)
```typescript
addListener(eventName: "downloadComplete", listenerFunc: (state: DownloadCompleteEvent) => void) => Promise'downloadComplete'
|
| **`listenerFunc`** | (state: DownloadCompleteEvent) => void
|
**Returns:** Promise<PluginListenerHandle>
**Since:** 4.0.0
--------------------
### addListener('majorAvailable', ...)
```typescript
addListener(eventName: "majorAvailable", listenerFunc: (state: MajorAvailableEvent) => void) => Promise'majorAvailable'
|
| **`listenerFunc`** | (state: MajorAvailableEvent) => void
|
**Returns:** Promise<PluginListenerHandle>
**Since:** 2.3.0
--------------------
### addListener('updateFailed', ...)
```typescript
addListener(eventName: "updateFailed", listenerFunc: (state: UpdateFailedEvent) => void) => Promise'updateFailed'
|
| **`listenerFunc`** | (state: UpdateFailedEvent) => void
|
**Returns:** Promise<PluginListenerHandle>
**Since:** 2.3.0
--------------------
### addListener('downloadFailed', ...)
```typescript
addListener(eventName: "downloadFailed", listenerFunc: (state: DownloadFailedEvent) => void) => Promise'downloadFailed'
|
| **`listenerFunc`** | (state: DownloadFailedEvent) => void
|
**Returns:** Promise<PluginListenerHandle>
**Since:** 4.0.0
--------------------
### addListener('appReloaded', ...)
```typescript
addListener(eventName: "appReloaded", listenerFunc: () => void) => Promise'appReloaded'
|
| **`listenerFunc`** | () => void
|
**Returns:** Promise<PluginListenerHandle>
**Since:** 4.3.0
--------------------
### addListener('appReady', ...)
```typescript
addListener(eventName: "appReady", listenerFunc: (state: AppReadyEvent) => void) => Promise'appReady'
|
| **`listenerFunc`** | (state: AppReadyEvent) => void
|
**Returns:** Promise<PluginListenerHandle>
**Since:** 5.1.0
--------------------
### Interfaces
#### AppReadyResult
| Prop | Type |
| ------------ | ------------------------------------------------- |
| **`bundle`** | BundleInfo
|
#### BundleInfo
| Prop | Type |
| ---------------- | ----------------------------------------------------- |
| **`id`** | string
|
| **`version`** | string
|
| **`downloaded`** | string
|
| **`checksum`** | string
|
| **`status`** | BundleStatus
|
#### UpdateUrl
| Prop | Type |
| --------- | ------------------- |
| **`url`** | string
|
#### StatsUrl
| Prop | Type |
| --------- | ------------------- |
| **`url`** | string
|
#### ChannelUrl
| Prop | Type |
| --------- | ------------------- |
| **`url`** | string
|
#### DownloadOptions
| Prop | Type | Description | Default | Since |
| ---------------- | ------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------- | ----- |
| **`url`** | string
| The URL of the bundle zip file (e.g: dist.zip) to be downloaded. (This can be any URL. E.g: Amazon S3, a GitHub tag, any other place you've hosted your bundle.) | | |
| **`version`** | string
| The version code/name of this bundle/version | | |
| **`sessionKey`** | string
| The session key for the update | undefined
| 4.0.0 |
| **`checksum`** | string
| The checksum for the update | undefined
| 4.0.0 |
#### BundleId
| Prop | Type |
| -------- | ------------------- |
| **`id`** | string
|
#### BundleListResult
| Prop | Type |
| ------------- | ------------------------- |
| **`bundles`** | BundleInfo[]
|
#### ResetOptions
| Prop | Type |
| ---------------------- | -------------------- |
| **`toLastSuccessful`** | boolean
|
#### CurrentBundleResult
| Prop | Type |
| ------------ | ------------------------------------------------- |
| **`bundle`** | BundleInfo
|
| **`native`** | string
|
#### MultiDelayConditions
| Prop | Type |
| --------------------- | ----------------------------- |
| **`delayConditions`** | DelayCondition[]
|
#### DelayCondition
| Prop | Type | Description |
| ----------- | --------------------------------------------------------- | ---------------------------------------- |
| **`kind`** | DelayUntilNext
| Set up delay conditions in setMultiDelay |
| **`value`** | string
| |
#### LatestVersion
| Prop | Type | Description | Since |
| ---------------- | -------------------- | -------------------------- | ----- |
| **`version`** | string
| Result of getLatest method | 4.0.0 |
| **`major`** | boolean
| | |
| **`message`** | string
| | |
| **`sessionKey`** | string
| | |
| **`error`** | string
| | |
| **`old`** | string
| | |
| **`url`** | string
| | |
#### ChannelRes
| Prop | Type | Description | Since |
| ------------- | ------------------- | ----------------------------- | ----- |
| **`status`** | string
| Current status of set channel | 4.7.0 |
| **`error`** | any
| | |
| **`message`** | any
| | |
#### SetChannelOptions
| Prop | Type |
| ----------------------- | -------------------- |
| **`channel`** | string
|
| **`triggerAutoUpdate`** | boolean
|
#### UnsetChannelOptions
| Prop | Type |
| ----------------------- | -------------------- |
| **`triggerAutoUpdate`** | boolean
|
#### GetChannelRes
| Prop | Type | Description | Since |
| -------------- | -------------------- | ----------------------------- | ----- |
| **`channel`** | string
| Current status of get channel | 4.8.0 |
| **`error`** | any
| | |
| **`message`** | any
| | |
| **`status`** | string
| | |
| **`allowSet`** | boolean
| | |
#### SetCustomIdOptions
| Prop | Type |
| -------------- | ------------------- |
| **`customId`** | string
|
#### BuiltinVersion
| Prop | Type |
| ------------- | ------------------- |
| **`version`** | string
|
#### DeviceId
| Prop | Type |
| -------------- | ------------------- |
| **`deviceId`** | string
|
#### PluginVersion
| Prop | Type |
| ------------- | ------------------- |
| **`version`** | string
|
#### AutoUpdateEnabled
| Prop | Type |
| ------------- | -------------------- |
| **`enabled`** | boolean
|
#### PluginListenerHandle
| Prop | Type |
| ------------ | ----------------------------------------- |
| **`remove`** | () => Promise<void>
|
#### DownloadEvent
| Prop | Type | Description | Since |
| ------------- | ------------------------------------------------- | ---------------------------------------------- | ----- |
| **`percent`** | number
| Current status of download, between 0 and 100. | 4.0.0 |
| **`bundle`** | BundleInfo
| | |
#### NoNeedEvent
| Prop | Type | Description | Since |
| ------------ | ------------------------------------------------- | ---------------------------------------------- | ----- |
| **`bundle`** | BundleInfo
| Current status of download, between 0 and 100. | 4.0.0 |
#### UpdateAvailableEvent
| Prop | Type | Description | Since |
| ------------ | ------------------------------------------------- | ---------------------------------------------- | ----- |
| **`bundle`** | BundleInfo
| Current status of download, between 0 and 100. | 4.0.0 |
#### DownloadCompleteEvent
| Prop | Type | Description | Since |
| ------------ | ------------------------------------------------- | ------------------------------------ | ----- |
| **`bundle`** | BundleInfo
| Emit when a new update is available. | 4.0.0 |
#### MajorAvailableEvent
| Prop | Type | Description | Since |
| ------------- | ------------------- | ------------------------------------------ | ----- |
| **`version`** | string
| Emit when a new major bundle is available. | 4.0.0 |
#### UpdateFailedEvent
| Prop | Type | Description | Since |
| ------------ | ------------------------------------------------- | ------------------------------------- | ----- |
| **`bundle`** | BundleInfo
| Emit when a update failed to install. | 4.0.0 |
#### DownloadFailedEvent
| Prop | Type | Description | Since |
| ------------- | ------------------- | -------------------------- | ----- |
| **`version`** | string
| Emit when a download fail. | 4.0.0 |
#### AppReadyEvent
| Prop | Type | Description | Since |
| ------------ | ------------------------------------------------- | ------------------------------------- | ----- |
| **`bundle`** | BundleInfo
| Emitted when the app is ready to use. | 5.2.0 |
| **`status`** | string
| | |
### Type Aliases
#### BundleStatus
"success" | "error" | "pending" | "downloading"
#### DelayUntilNext
"background" | "kill" | "nativeVersion" | "date"
import { CapacitorUpdater } from '@capgo/capacitor-updater';
CapacitorUpdater.addListener('download', (info: any) => {
console.log('download was fired', info.percent);
});
On iOS, Apple don't allow you to show a message when the app is updated, so you can't show a progress bar.
jamesyoung1337 Thank you so much for your guidance and support, it was impossible to make this plugin work without you.