* Handle TargetBinaryVersionMismatch * fix readme, add binary version mismatch example to docs * fix docs, typings
This commit is contained in:
Родитель
26d84b5a81
Коммит
85e094f7e1
24
CodePush.js
24
CodePush.js
|
@ -8,7 +8,7 @@ import log from "./logging";
|
|||
let NativeCodePush = require("react-native").NativeModules.CodePush;
|
||||
const PackageMixins = require("./package-mixins")(NativeCodePush);
|
||||
|
||||
async function checkForUpdate(deploymentKey = null) {
|
||||
async function checkForUpdate(deploymentKey = null, handleBinaryVersionMismatchCallback = null) {
|
||||
/*
|
||||
* Before we ask the server if an update exists, we
|
||||
* need to retrieve three pieces of information from the
|
||||
|
@ -19,7 +19,6 @@ async function checkForUpdate(deploymentKey = null) {
|
|||
* different from the CodePush update they have already installed.
|
||||
*/
|
||||
const nativeConfig = await getConfiguration();
|
||||
|
||||
/*
|
||||
* If a deployment key was explicitly provided,
|
||||
* then let's override the one we retrieved
|
||||
|
@ -76,6 +75,9 @@ async function checkForUpdate(deploymentKey = null) {
|
|||
(!localPackage || localPackage._isDebugOnly) && config.packageHash === update.packageHash) {
|
||||
if (update && update.updateAppVersion) {
|
||||
log("An update is available but it is not targeting the binary version of your app.");
|
||||
if (handleBinaryVersionMismatchCallback && typeof handleBinaryVersionMismatchCallback === "function") {
|
||||
handleBinaryVersionMismatchCallback(update)
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
|
@ -237,7 +239,7 @@ const sync = (() => {
|
|||
let syncInProgress = false;
|
||||
const setSyncCompleted = () => { syncInProgress = false; };
|
||||
|
||||
return (options = {}, syncStatusChangeCallback, downloadProgressCallback) => {
|
||||
return (options = {}, syncStatusChangeCallback, downloadProgressCallback, handleBinaryVersionMismatchCallback) => {
|
||||
let syncStatusCallbackWithTryCatch, downloadProgressCallbackkWithTryCatch;
|
||||
if (typeof syncStatusChangeCallback === "function") {
|
||||
syncStatusCallbackWithTryCatch = (...args) => {
|
||||
|
@ -267,7 +269,7 @@ const sync = (() => {
|
|||
}
|
||||
|
||||
syncInProgress = true;
|
||||
const syncPromise = syncInternal(options, syncStatusCallbackWithTryCatch, downloadProgressCallbackkWithTryCatch);
|
||||
const syncPromise = syncInternal(options, syncStatusCallbackWithTryCatch, downloadProgressCallbackkWithTryCatch, handleBinaryVersionMismatchCallback);
|
||||
syncPromise
|
||||
.then(setSyncCompleted)
|
||||
.catch(setSyncCompleted);
|
||||
|
@ -285,7 +287,7 @@ const sync = (() => {
|
|||
* releases, and displaying a standard confirmation UI to the end-user
|
||||
* when an update is available.
|
||||
*/
|
||||
async function syncInternal(options = {}, syncStatusChangeCallback, downloadProgressCallback) {
|
||||
async function syncInternal(options = {}, syncStatusChangeCallback, downloadProgressCallback, handleBinaryVersionMismatchCallback) {
|
||||
let resolvedInstallMode;
|
||||
const syncOptions = {
|
||||
deploymentKey: null,
|
||||
|
@ -340,7 +342,7 @@ async function syncInternal(options = {}, syncStatusChangeCallback, downloadProg
|
|||
await CodePush.notifyApplicationReady();
|
||||
|
||||
syncStatusChangeCallback(CodePush.SyncStatus.CHECKING_FOR_UPDATE);
|
||||
const remotePackage = await checkForUpdate(syncOptions.deploymentKey);
|
||||
const remotePackage = await checkForUpdate(syncOptions.deploymentKey, handleBinaryVersionMismatchCallback);
|
||||
|
||||
const doDownloadAndInstall = async () => {
|
||||
syncStatusChangeCallback(CodePush.SyncStatus.DOWNLOADING_PACKAGE);
|
||||
|
@ -472,7 +474,15 @@ function codePushify(options = {}) {
|
|||
}
|
||||
}
|
||||
|
||||
CodePush.sync(options, syncStatusCallback, downloadProgressCallback);
|
||||
let handleBinaryVersionMismatchCallback;
|
||||
if (rootComponentInstance && rootComponentInstance.codePushOnBinaryVersionMismatch) {
|
||||
handleBinaryVersionMismatchCallback = rootComponentInstance.codePushOnBinaryVersionMismatch;
|
||||
if (rootComponentInstance instanceof React.Component) {
|
||||
handleBinaryVersionMismatchCallback = handleBinaryVersionMismatchCallback.bind(rootComponentInstance);
|
||||
}
|
||||
}
|
||||
|
||||
CodePush.sync(options, syncStatusCallback, downloadProgressCallback, handleBinaryVersionMismatchCallback);
|
||||
if (options.checkFrequency === CodePush.CheckFrequency.ON_APP_RESUME) {
|
||||
ReactNative.AppState.addEventListener("change", (newState) => {
|
||||
newState === "active" && CodePush.sync(options, syncStatusCallback, downloadProgressCallback);
|
||||
|
|
|
@ -179,11 +179,18 @@ See [disallowRestart](#codepushdisallowrestart) for an example of how this metho
|
|||
#### codePush.checkForUpdate
|
||||
|
||||
```javascript
|
||||
codePush.checkForUpdate(deploymentKey: String = null): Promise<RemotePackage>;
|
||||
codePush.checkForUpdate(deploymentKey: String = null, handleBinaryVersionMismatchCallback: (update: RemotePackage) => void): Promise<RemotePackage>;
|
||||
```
|
||||
|
||||
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 `Info.plist` file (iOS), or `MainActivity.java` file (Android), 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.
|
||||
|
||||
Second optional parameter `handleBinaryVersionMismatchCallback` is an optional callback function that can be used to notify user if there are any binary update.
|
||||
E.g. consider a use-case where currently installed binary version is 1.0.1 with label(codepush label) v1. Later native code was changed in the dev cycle and binary version was updated to 1.0.2. When code-push update check is triggered we ignore updates having binary version mismatch (because the update is not targeting to the binary version of currently installed app). In this case installed app (1.0.1) will ignore the update targeting version 1.0.2. You can use `handleBinaryVersionMismatchCallback` to provide a hook to handle such situations.
|
||||
|
||||
**NOTE:**
|
||||
Be cautious to use Alerts within this callback if you are developing iOS application, due to [App Store](https://developer.apple.com/app-store/review/guidelines/) review process:
|
||||
> Apps must not force users to rate the app, review the app, download other apps, or other similar actions in order to access functionality, content, or use of the app.
|
||||
|
||||
This method returns a `Promise` which resolves to one of two possible values:
|
||||
|
||||
1. `null` if there is no update available. This can occur in the following scenarios:
|
||||
|
@ -356,7 +363,7 @@ This method is for advanced scenarios, and is primarily useful when the followin
|
|||
#### codePush.sync
|
||||
|
||||
```javascript
|
||||
codePush.sync(options: Object, syncStatusChangeCallback: function(syncStatus: Number), downloadProgressCallback: function(progress: DownloadProgress)): Promise<Number>;
|
||||
codePush.sync(options: Object, syncStatusChangeCallback: function(syncStatus: Number), downloadProgressCallback: function(progress: DownloadProgress), handleBinaryVersionMismatchCallback: function(update: RemotePackage)): Promise<Number>;
|
||||
```
|
||||
|
||||
Synchronizes your app's JavaScript bundle and image assets with the latest release to the configured deployment. Unlike the [checkForUpdate](#codepushcheckforupdate) 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.
|
||||
|
@ -429,7 +436,7 @@ codePush.sync({
|
|||
});
|
||||
```
|
||||
|
||||
In addition to the options, the `sync` method also accepts two optional function parameters which allow you to subscribe to the lifecycle of the `sync` "pipeline" in order to display additional UI as needed (e.g. a "checking for update modal or a download progress modal):
|
||||
In addition to the options, the `sync` method also accepts several optional function parameters which allow you to subscribe to the lifecycle of the `sync` "pipeline" in order to display additional UI as needed (e.g. a "checking for update modal or a download progress modal):
|
||||
|
||||
* __syncStatusChangedCallback__ *((syncStatus: Number) => void)* - Called when the sync process moves from one stage to another in the overall update process. The method is called with a status code which represents the current state, and can be any of the [`SyncStatus`](#syncstatus) values.
|
||||
|
||||
|
@ -439,6 +446,9 @@ In addition to the options, the `sync` method also accepts two optional function
|
|||
|
||||
* __receivedBytes__ *(Number)* - The number of bytes downloaded thus far, which can be used to track download progress.
|
||||
|
||||
* __handleBinaryVersionMismatchCallback__ *((update: RemotePackage) => void)* -
|
||||
Called when there are any binary update available. The method is called with a [`RemotePackage`](#remotepackage) object. Refer to [codePush.checkForUpdate](#codepushcheckforupdate) section for more details.
|
||||
|
||||
Example Usage:
|
||||
|
||||
```javascript
|
||||
|
|
|
@ -19,6 +19,7 @@ interface Promise<T> {
|
|||
|
||||
export type DowloadProgressCallback = (progress: DownloadProgress) => void;
|
||||
export type SyncStatusChangedCallback = (status: CodePush.SyncStatus) => void;
|
||||
export type HandleBinaryVersionMismatchCallback = (update: RemotePackage) => void;
|
||||
|
||||
export interface CodePushOptions extends SyncOptions {
|
||||
/**
|
||||
|
@ -245,8 +246,10 @@ declare namespace CodePush {
|
|||
* Asks the CodePush service whether the configured app deployment has an update available.
|
||||
*
|
||||
* @param deploymentKey The deployment key to use to query the CodePush server for an update.
|
||||
*
|
||||
* @param handleBinaryVersionMismatchCallback An optional callback for handling target binary version mismatch
|
||||
*/
|
||||
function checkForUpdate(deploymentKey?: string): Promise<RemotePackage>;
|
||||
function checkForUpdate(deploymentKey?: string, handleBinaryVersionMismatchCallback?: HandleBinaryVersionMismatchCallback): Promise<RemotePackage>;
|
||||
|
||||
/**
|
||||
* Retrieves the metadata for an installed update (e.g. description, mandatory).
|
||||
|
@ -283,8 +286,9 @@ declare namespace CodePush {
|
|||
* @param options Options used to configure the end-user update experience (e.g. show an prompt?, install the update immediately?).
|
||||
* @param syncStatusChangedCallback An optional callback that allows tracking the status of the sync operation, as opposed to simply checking the resolved state via the returned Promise.
|
||||
* @param downloadProgressCallback An optional callback that allows tracking the progress of an update while it is being downloaded.
|
||||
* @param handleBinaryVersionMismatchCallback An optional callback for handling target binary version mismatch
|
||||
*/
|
||||
function sync(options?: SyncOptions, syncStatusChangedCallback?: SyncStatusChangedCallback, downloadProgressCallback?: DowloadProgressCallback): Promise<SyncStatus>;
|
||||
function sync(options?: SyncOptions, syncStatusChangedCallback?: SyncStatusChangedCallback, downloadProgressCallback?: DowloadProgressCallback, handleBinaryVersionMismatchCallback?: HandleBinaryVersionMismatchCallback): Promise<SyncStatus>;
|
||||
|
||||
/**
|
||||
* Indicates when you would like an installed update to actually be applied.
|
||||
|
|
Загрузка…
Ссылка в новой задаче