Code Push

Improve this doc

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

  1. Install the Cordova and Ionic Native plugins:
    $ ionic cordova plugin add cordova-plugin-code-push
    $ npm install --save @ionic-native/code-push
    
  2. Add this plugin to your app's module

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()

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:

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>

API

Native

General