diff --git a/README.md b/README.md index 34723096..f6c5de4a 100644 --- a/README.md +++ b/README.md @@ -240,12 +240,12 @@ Additionally, the following objects and enums are also exposed globally as part ### codePush.checkForUpdate ```javascript -codePush.checkForUpdate(onSuccess, onError?, deploymentKey?: String); +codePush.checkForUpdate(onSuccess, onError?, deploymentKey?, onBinaryUpdate?); ``` Queries the CodePush service to see whether the configured app deployment has an update available. By default, it will use the deployment key that is configured in your `config.xml` file, but you can override that by specifying a value via the optional `deploymentKey` parameter. This can be useful when you want to dynamically "redirect" a user to a specific deployment, such as allowing "Early access" via an easter egg or a user setting switch. -When the update check completes, it will trigger the `onUpdateCheck` callback with one of two possible values: +When the update check completes, it will trigger the `onSuccess` callback with one of two possible values: 1. `null` if there is no update available. This occurs in the following scenarios: @@ -277,6 +277,8 @@ codePush.checkForUpdate(function (update) { }); ``` +- __onBinaryUpdate__: Optional callback that is invoked when there is an update available that is targeting a newer binary version than you are currently running. + ### codePush.getCurrentPackage ```javascript @@ -381,7 +383,7 @@ Immediately restarts the app. This method is for advanced scenarios, and is prim ### codePush.sync ```javascript -codePush.sync(syncCallback?, syncOptions?, downloadProgress?, syncErrback?); +codePush.sync(syncCallback?, syncOptions?, downloadProgress?, syncErrback?, onBinaryUpdate?); ``` Synchronizes your app's code and images with the latest release to the configured deployment. Unlike the `checkForUpdate` method, which simply checks for the presence of an update, and let's you control what to do next, `sync` handles the update check, download and installation experience for you. @@ -420,6 +422,10 @@ While the sync method tries to make it easy to perform silent and active updates - __receivedBytes__ *(Number)* - The number of bytes downloaded thus far, which can be used to track download progress. +- __syncErrback__: Optional callback that is invoked in the event of an error. The callback takes one error parameter, containing the details of the error. + +- __onBinaryUpdate__: Optional callback that is invoked when there is an update available that is targeting a newer binary version than you are currently running. + #### SyncOptions While the `sync` method tries to make it easy to perform silent and active updates with little configuration, it accepts an "options" object that allows you to customize numerous aspects of the default behavior mentioned above: diff --git a/bin/www/codePush.js b/bin/www/codePush.js index d4a4e376..86222817 100644 --- a/bin/www/codePush.js +++ b/bin/www/codePush.js @@ -82,7 +82,7 @@ var CodePush = (function () { } }); }; - CodePush.prototype.checkForUpdate = function (querySuccess, queryError, deploymentKey) { + CodePush.prototype.checkForUpdate = function (querySuccess, queryError, deploymentKey, binaryUpdateCallback) { try { var callback = function (error, remotePackageOrUpdateNotification) { if (error) { @@ -96,6 +96,7 @@ var CodePush = (function () { if (remotePackageOrUpdateNotification) { if (remotePackageOrUpdateNotification.updateAppVersion) { CodePushUtil.logMessage("An update is available, but it is targeting a newer binary version than you are currently running."); + binaryUpdateCallback && binaryUpdateCallback(remotePackageOrUpdateNotification); appUpToDate(); } else { @@ -160,7 +161,7 @@ var CodePush = (function () { CodePushUtil.invokeErrorCallback(new Error("An error occurred while querying for updates." + CodePushUtil.getErrorMessage(e)), queryError); } }; - CodePush.prototype.sync = function (syncCallback, syncOptions, downloadProgress, syncErrback) { + CodePush.prototype.sync = function (syncCallback, syncOptions, downloadProgress, syncErrback, binaryUpdateCallback) { if (CodePush.SyncInProgress) { CodePushUtil.logMessage("Sync already in progress."); syncCallback && syncCallback(SyncStatus.IN_PROGRESS); @@ -183,10 +184,10 @@ var CodePush = (function () { syncCallback && syncCallback(result); }; CodePush.SyncInProgress = true; - this.syncInternal(syncCallbackAndUpdateSyncInProgress, syncOptions, downloadProgress); + this.syncInternal(syncCallbackAndUpdateSyncInProgress, syncOptions, downloadProgress, binaryUpdateCallback); } }; - CodePush.prototype.syncInternal = function (syncCallback, syncOptions, downloadProgress) { + CodePush.prototype.syncInternal = function (syncCallback, syncOptions, downloadProgress, onBinaryUpdate) { if (!syncOptions) { syncOptions = this.getDefaultSyncOptions(); } @@ -276,7 +277,7 @@ var CodePush = (function () { } }; syncCallback && syncCallback(null, SyncStatus.CHECKING_FOR_UPDATE); - window.codePush.checkForUpdate(onUpdate, onError, syncOptions.deploymentKey); + window.codePush.checkForUpdate(onUpdate, onError, syncOptions.deploymentKey, onBinaryUpdate); }; CodePush.prototype.getDefaultSyncOptions = function () { if (!CodePush.DefaultSyncOptions) { diff --git a/typings/codePush.d.ts b/typings/codePush.d.ts index 65199c94..c01f0674 100644 --- a/typings/codePush.d.ts +++ b/typings/codePush.d.ts @@ -263,8 +263,9 @@ interface CodePushCordovaPlugin { * A null package means the application is up to date for the current native application version. * @param queryError Optional callback invoked in case of an error. * @param deploymentKey Optional deployment key that overrides the config.xml setting. + * @param binaryUpdateCallback Optional callback invoked when there is an update available, but it is targeting a newer binary version than you are currently running. */ - checkForUpdate(querySuccess: SuccessCallback, queryError?: ErrorCallback, deploymentKey?: string): void; + checkForUpdate(querySuccess: SuccessCallback, queryError?: ErrorCallback, deploymentKey?: string, binaryUpdateCallback?: SuccessCallback): void; /** * Notifies the plugin that the update operation succeeded and that the application is ready. @@ -301,9 +302,10 @@ interface CodePushCordovaPlugin { * The callback will be called only once, and the possible statuses are defined by the SyncStatus enum. * @param syncOptions Optional SyncOptions parameter configuring the behavior of the sync operation. * @param downloadProgress Optional callback invoked during the download process. It is called several times with one DownloadProgress parameter. - * + * @param syncErrback Optional errback invoked if an error occurs. The callback will be called only once + * @param binaryUpdateCallback Optional callback invoked when there is an update available, but it is targeting a newer binary version than you are currently running. */ - sync(syncCallback?: SuccessCallback, syncOptions?: SyncOptions, downloadProgress?: SuccessCallback): void; + sync(syncCallback?: SuccessCallback, syncOptions?: SyncOptions, downloadProgress?: SuccessCallback, syncErrback?: ErrorCallback, binaryUpdateCallback?: SuccessCallback): void; } /** diff --git a/www/codePush.ts b/www/codePush.ts index 4062c1f4..bef648b5 100644 --- a/www/codePush.ts +++ b/www/codePush.ts @@ -147,8 +147,9 @@ class CodePush implements CodePushCordovaPlugin { * A null package means the application is up to date for the current native application version. * @param queryError Optional callback invoked in case of an error. * @param deploymentKey Optional deployment key that overrides the config.xml setting. + * @param binaryUpdateCallback Optional callback invoked when there is an update available that is targeting a newer binary version than you are currently running. */ - public checkForUpdate(querySuccess: SuccessCallback, queryError?: ErrorCallback, deploymentKey?: string): void { + public checkForUpdate(querySuccess: SuccessCallback, queryError?: ErrorCallback, deploymentKey?: string, binaryUpdateCallback?: SuccessCallback): void { try { var callback: Callback = (error: Error, remotePackageOrUpdateNotification: IRemotePackage | NativeUpdateNotification) => { if (error) { @@ -162,8 +163,9 @@ class CodePush implements CodePushCordovaPlugin { if (remotePackageOrUpdateNotification) { if ((remotePackageOrUpdateNotification).updateAppVersion) { - /* There is an update available for a different version. In the current version of the plugin, we treat that as no update. */ + /* There is an update available for a different version. */ CodePushUtil.logMessage("An update is available, but it is targeting a newer binary version than you are currently running."); + binaryUpdateCallback && binaryUpdateCallback(remotePackageOrUpdateNotification); appUpToDate(); } else { /* There is an update available for the current version. */ @@ -248,9 +250,9 @@ class CodePush implements CodePushCordovaPlugin { * @param syncOptions Optional SyncOptions parameter configuring the behavior of the sync operation. * @param downloadProgress Optional callback invoked during the download process. It is called several times with one DownloadProgress parameter. * @param syncErrback Optional errback invoked if an error occurs. The callback will be called only once - * + * @param binaryUpdateCallback Optional callback invoked when there is an update available that is targeting a newer binary version than you are currently running. */ - public sync(syncCallback?: SuccessCallback, syncOptions?: SyncOptions, downloadProgress?: SuccessCallback, syncErrback?: ErrorCallback): void { + public sync(syncCallback?: SuccessCallback, syncOptions?: SyncOptions, downloadProgress?: SuccessCallback, syncErrback?: ErrorCallback, binaryUpdateCallback?: SuccessCallback): void { /* Check if a sync is already in progress */ if (CodePush.SyncInProgress) { /* A sync is already in progress */ @@ -285,7 +287,7 @@ class CodePush implements CodePushCordovaPlugin { /* Begin the sync */ CodePush.SyncInProgress = true; - this.syncInternal(syncCallbackAndUpdateSyncInProgress, syncOptions, downloadProgress); + this.syncInternal(syncCallbackAndUpdateSyncInProgress, syncOptions, downloadProgress, binaryUpdateCallback); } } @@ -299,9 +301,9 @@ class CodePush implements CodePushCordovaPlugin { * The callback will be called only once, and the possible statuses are defined by the SyncStatus enum. * @param syncOptions Optional SyncOptions parameter configuring the behavior of the sync operation. * @param downloadProgress Optional callback invoked during the download process. It is called several times with one DownloadProgress parameter. - * + * @param onBinaryUpdate Optional callback invoked when there is an update available, but it is targeting a newer binary version than you are currently running. */ - private syncInternal(syncCallback?: Callback, syncOptions?: SyncOptions, downloadProgress?: SuccessCallback): void { + private syncInternal(syncCallback?: Callback, syncOptions?: SyncOptions, downloadProgress?: SuccessCallback, onBinaryUpdate?: SuccessCallback): void { /* No options were specified, use default */ if (!syncOptions) { @@ -410,7 +412,7 @@ class CodePush implements CodePushCordovaPlugin { }; syncCallback && syncCallback(null, SyncStatus.CHECKING_FOR_UPDATE); - window.codePush.checkForUpdate(onUpdate, onError, syncOptions.deploymentKey); + window.codePush.checkForUpdate(onUpdate, onError, syncOptions.deploymentKey, onBinaryUpdate); } /**