Code Push

Improve this doc

$ ionic plugin add cordova-plugin-code-push
$ npm install --save @ionic-native/code-push

Repo: https://github.com/Microsoft/cordova-plugin-code-push

CodePush plugin for Cordova by Microsoft that supports iOS and Android.

For more info, please see https://github.com/ksachdeva/ionic2-code-push-example

Supported platforms

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(packageSuccess, packageError)

Get the current package information.

Param Type Details
packageSuccess

Callback invoked with the currently deployed package information.

packageError

Optional callback invoked in case of an error.

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 happends 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(querySuccess, queryError, deploymentKey)

Checks with the CodePush server if an update package is available for download.

Param Type Details
querySuccess

Callback invoked in case of a successful response from the server. The callback takes one RemotePackage parameter. A non-null package is a valid update. A null package means the application is up to date for the current native application version.

queryError

Optional callback invoked in case of an error.

deploymentKey

Optional deployment key that overrides the config.xml setting.

Returns: Promise<IRemotePackage>

notifyApplicationReady(notifySucceeded, notifyFailed)

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.

Param Type Details
notifySucceeded

Optional callback invoked if the plugin was successfully notified.

notifyFailed

Optional callback invoked in case of an error during notifying the plugin.

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(syncCallback, 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:

Param Type Details
syncCallback

Optional callback to be called with the status of the sync operation.

syncOptions

Optional SyncOptions parameter configuring the behavior of the sync operation.

downloadProgress

Optional callback invoked during the download process. It is called several times with one DownloadProgress parameter.

Returns: Observable<SyncStatus>

API

Native

General