Code Push
CodePush plugin for Cordova by Microsoft that supports iOS and Android.
For more info, please see https://github.com/Dellos7/example-cordova-code-push-plugin
Repo: https://github.com/Microsoft/cordova-plugin-code-push
Installation
- Install the Cordova and Ionic Native plugins:
$ ionic cordova plugin add cordova-plugin-code-push $ npm install --save @ionic-native/code-push@4
- Add this plugin to your app's module
Supported platforms
- Android
- iOS
Usage
import { CodePush } from '@ionic-native/code-push';
constructor(private codePush: CodePush) { }
...
// note - mostly error & completed methods of observable will not fire
// as syncStatus will contain the current state of the update
this.codePush.sync().subscribe((syncStatus) => console.log(syncStatus));
const downloadProgress = (progress) => { console.log(`Downloaded ${progress.receivedBytes} of ${progress.totalBytes}`); }
this.codePush.sync({}, downloadProgress).subscribe((syncStatus) => console.log(syncStatus));
Instance Members
getCurrentPackage()
Get the current package information.
Returns: Promise<ILocalPackage>
getPendingPackage()
Gets the pending package information, if any. A pending package is one that has been installed but the application still runs the old code. This happens only after a package has been installed using ON_NEXT_RESTART or ON_NEXT_RESUME mode, but the application was not restarted/resumed yet.
Returns: Promise<ILocalPackage>
checkForUpdate(deploymentKey)
Checks with the CodePush server if an update package is available for download.
Param | Type | Details |
---|---|---|
deploymentKey |
string
|
Optional deployment key that overrides the config.xml setting.Optional |
Returns: Promise<IRemotePackage>
notifyApplicationReady()
Notifies the plugin that the update operation succeeded and that the application is ready. Calling this function is required on the first run after an update. On every subsequent application run, calling this function is a noop. If using sync API, calling this function is not required since sync calls it internally.
Returns: Promise<void>
restartApplication()
Reloads the application. If there is a pending update package installed using ON_NEXT_RESTART or ON_NEXT_RESUME modes, the update will be immediately visible to the user. Otherwise, calling this function will simply reload the current version of the application.
Returns: Promise<void>
sync(syncOptions, downloadProgress)
Convenience method for installing updates in one method call. This method is provided for simplicity, and its behavior can be replicated by using window.codePush.checkForUpdate(), RemotePackage’s download() and LocalPackage’s install() methods.
The algorithm of this method is the following:
- Checks for an update on the CodePush server.
- If an update is available - If the update is mandatory and the alertMessage is set in options, the user will be informed that the application will be updated to the latest version. The update package will then be downloaded and applied. - If the update is not mandatory and the confirmMessage is set in options, the user will be asked if they want to update to the latest version. If they decline, the syncCallback will be invoked with SyncStatus.UPDATE_IGNORED. - Otherwise, the update package will be downloaded and applied with no user interaction.
- If no update is available on the server, or if a previously rolled back update is available and the ignoreFailedUpdates is set to true, the syncCallback will be invoked with the SyncStatus.UP_TO_DATE.
- If an error occurs during checking for update, downloading or installing it, the syncCallback will be invoked with the SyncStatus.ERROR.
Param | Type | Details |
---|---|---|
syncOptions |
SyncOptions
|
Optional SyncOptions parameter configuring the behavior of the sync operation.Optional |
downloadProgress |
SuccessCallback<DownloadProgress>
|
Optional callback invoked during the download process. It is called several times with one DownloadProgress parameter.Optional |
Returns: Observable<SyncStatus>