react-native-code-push
Advanced tools
Comparing version 1.10.2-beta to 1.10.3-beta
@@ -103,8 +103,12 @@ import { AcquisitionManager as Sdk } from "code-push/script/acquisition-sdk"; | ||
async function getCurrentPackage() { | ||
const localPackage = await NativeCodePush.getCurrentPackage(); | ||
if (localPackage) { | ||
localPackage.failedInstall = await NativeCodePush.isFailedUpdate(localPackage.packageHash); | ||
localPackage.isFirstRun = await NativeCodePush.isFirstRun(localPackage.packageHash); | ||
return await getUpdateMetadata(CodePush.UpdateState.LATEST); | ||
} | ||
async function getUpdateMetadata(updateState) { | ||
const updateMetadata = await NativeCodePush.getUpdateMetadata(updateState || CodePush.UpdateState.RUNNING); | ||
if (updateMetadata) { | ||
updateMetadata.failedInstall = await NativeCodePush.isFailedUpdate(updateMetadata.packageHash); | ||
updateMetadata.isFirstRun = await NativeCodePush.isFirstRun(updateMetadata.packageHash); | ||
} | ||
return localPackage; | ||
return updateMetadata; | ||
} | ||
@@ -387,43 +391,50 @@ | ||
if (NativeCodePush) { | ||
CodePush = { | ||
AcquisitionSdk: Sdk, | ||
checkForUpdate, | ||
getConfiguration, | ||
getCurrentPackage, | ||
log, | ||
notifyApplicationReady, | ||
restartApp, | ||
setUpTestDependencies, | ||
sync, | ||
InstallMode: { | ||
IMMEDIATE: NativeCodePush.codePushInstallModeImmediate, // Restart the app immediately | ||
ON_NEXT_RESTART: NativeCodePush.codePushInstallModeOnNextRestart, // Don't artificially restart the app. Allow the update to be "picked up" on the next app restart | ||
ON_NEXT_RESUME: NativeCodePush.codePushInstallModeOnNextResume // Restart the app the next time it is resumed from the background | ||
}, | ||
SyncStatus: { | ||
CHECKING_FOR_UPDATE: 0, | ||
AWAITING_USER_ACTION: 1, | ||
DOWNLOADING_PACKAGE: 2, | ||
INSTALLING_UPDATE: 3, | ||
UP_TO_DATE: 4, // The running app is up-to-date | ||
UPDATE_IGNORED: 5, // The app had an optional update and the end-user chose to ignore it | ||
UPDATE_INSTALLED: 6, // The app had an optional/mandatory update that was successfully downloaded and is about to be installed. | ||
SYNC_IN_PROGRESS: 7, // There is an ongoing "sync" operation in progress. | ||
UNKNOWN_ERROR: -1 | ||
}, | ||
DEFAULT_UPDATE_DIALOG: { | ||
appendReleaseDescription: false, | ||
descriptionPrefix: " Description: ", | ||
mandatoryContinueButtonLabel: "Continue", | ||
mandatoryUpdateMessage: "An update is available that must be installed.", | ||
optionalIgnoreButtonLabel: "Ignore", | ||
optionalInstallButtonLabel: "Install", | ||
optionalUpdateMessage: "An update is available. Would you like to install it?", | ||
title: "Update available" | ||
} | ||
CodePush = { | ||
AcquisitionSdk: Sdk, | ||
checkForUpdate, | ||
getConfiguration, | ||
getCurrentPackage, | ||
getUpdateMetadata, | ||
log, | ||
notifyAppReady: notifyApplicationReady, | ||
notifyApplicationReady, | ||
restartApp, | ||
setUpTestDependencies, | ||
sync, | ||
InstallMode: { | ||
IMMEDIATE: NativeCodePush.codePushInstallModeImmediate, // Restart the app immediately | ||
ON_NEXT_RESTART: NativeCodePush.codePushInstallModeOnNextRestart, // Don't artificially restart the app. Allow the update to be "picked up" on the next app restart | ||
ON_NEXT_RESUME: NativeCodePush.codePushInstallModeOnNextResume // Restart the app the next time it is resumed from the background | ||
}, | ||
SyncStatus: { | ||
CHECKING_FOR_UPDATE: 0, | ||
AWAITING_USER_ACTION: 1, | ||
DOWNLOADING_PACKAGE: 2, | ||
INSTALLING_UPDATE: 3, | ||
UP_TO_DATE: 4, // The running app is up-to-date | ||
UPDATE_IGNORED: 5, // The app had an optional update and the end-user chose to ignore it | ||
UPDATE_INSTALLED: 6, // The app had an optional/mandatory update that was successfully downloaded and is about to be installed. | ||
SYNC_IN_PROGRESS: 7, // There is an ongoing "sync" operation in progress. | ||
UNKNOWN_ERROR: -1 | ||
}, | ||
UpdateState: { | ||
RUNNING: NativeCodePush.codePushUpdateStateRunning, | ||
PENDING: NativeCodePush.codePushUpdateStatePending, | ||
LATEST: NativeCodePush.codePushUpdateStateLatest | ||
}, | ||
DEFAULT_UPDATE_DIALOG: { | ||
appendReleaseDescription: false, | ||
descriptionPrefix: " Description: ", | ||
mandatoryContinueButtonLabel: "Continue", | ||
mandatoryUpdateMessage: "An update is available that must be installed.", | ||
optionalIgnoreButtonLabel: "Ignore", | ||
optionalInstallButtonLabel: "Install", | ||
optionalUpdateMessage: "An update is available. Would you like to install it?", | ||
title: "Update available" | ||
} | ||
}; | ||
} else { | ||
log("The CodePush module doesn't appear to be properly installed. Please double-check that everything is setup correctly."); | ||
log("The CodePush module doesn't appear to be properly installed. Please double-check that everything is setup correctly."); | ||
} | ||
module.exports = CodePush; | ||
module.exports = CodePush; |
{ | ||
"name": "react-native-code-push", | ||
"version": "1.10.2-beta", | ||
"version": "1.10.3-beta", | ||
"description": "React Native plugin for the CodePush service", | ||
@@ -26,3 +26,3 @@ "main": "CodePush.js", | ||
"ios": { | ||
"sharedLibraries": ["libz"] | ||
"sharedLibraries": ["libz"] | ||
}, | ||
@@ -32,5 +32,5 @@ "params": [{ | ||
"name": "androidDeploymentKey", | ||
"message": "What is your CodePush deployment key for Android (hit <ENTER> to ignore)" | ||
"message": "What is your CodePush deployment key for Android (hit <ENTER> to ignore)" | ||
}] | ||
} | ||
} |
@@ -196,7 +196,9 @@ // Type definitions for React Native CodePush pligin. | ||
function checkForUpdate(deploymentKey?: string): ReactNativePromise<RemotePackage>; | ||
/** | ||
* Retrieves the metadata about the currently installed update (e.g. description, installation time, size). | ||
* Retrieves the metadata for an installed update (e.g. description, mandatory). | ||
* | ||
* @param updateState The state of the update you want to retrieve the metadata for. Defaults to UpdateState.RUNNING. | ||
*/ | ||
function getCurrentPackage(): ReactNativePromise<LocalPackage>; | ||
function getUpdateMetadata(updateState?: UpdateState) : ReactNativePromise<LocalPackage>; | ||
@@ -206,3 +208,3 @@ /** | ||
*/ | ||
function notifyApplicationReady(): ReactNativePromise<void>; | ||
function notifyAppReady(): ReactNativePromise<void>; | ||
@@ -223,3 +225,3 @@ /** | ||
*/ | ||
function sync(options?: SyncOptions, syncStatusChangedCallback?: SyncStatusChangedCallback, downloadProgressCallback?: DowloadProgressCallback): __React.Promise<SyncStatus>; | ||
function sync(options?: SyncOptions, syncStatusChangedCallback?: SyncStatusChangedCallback, downloadProgressCallback?: DowloadProgressCallback): ReactNativePromise<SyncStatus>; | ||
@@ -247,2 +249,5 @@ /** | ||
/** | ||
* Indicates the current status of a sync operation. | ||
*/ | ||
enum SyncStatus { | ||
@@ -298,2 +303,25 @@ /** | ||
} | ||
/** | ||
* Indicates the state that an update is currently in. | ||
*/ | ||
enum UpdateState { | ||
/** | ||
* Indicates that an update represents the | ||
* version of the app that is currently running. | ||
*/ | ||
RUNNING, | ||
/** | ||
* Indicates than an update has been installed, but the | ||
* app hasn't been restarted yet in order to apply it. | ||
*/ | ||
PENDING, | ||
/** | ||
* Indicates than an update represents the latest available | ||
* release, and can be either currently running or pending. | ||
*/ | ||
LATEST | ||
} | ||
} | ||
@@ -300,0 +328,0 @@ |
@@ -51,4 +51,4 @@ # React Native Module for CodePush | ||
| v0.15.0-v0.18.0 | v1.4.0-v1.6.0 *(introduced iOS asset support)* | | ||
| v0.19.0-v0.24.0 | v1.7.0+ *(introduced Android asset support)* | | ||
| v0.25.0+ | TBD :) We work hard to respond to new RN releases, but they do occasionally break us. We will update this chart with each RN release, so that users can check to see what our "official" support is. | ||
| v0.19.0-v0.25.0 | v1.7.0+ *(introduced Android asset support)* | | ||
| v0.26.0+ | TBD :) We work hard to respond to new RN releases, but they do occasionally break us. We will update this chart with each RN release, so that users can check to see what our "official" support is. | ||
@@ -312,4 +312,14 @@ ## Supported Components | ||
If an update is available, it will be silently downloaded, and installed the next time the app is restarted (either explicitly by the end user or by the OS), which ensures the least invasive experience for your end users. If an available update is mandatory, then it will be installed immediately, ensuring that the end user gets it as soon as possible. Additionally, if you would like to display a confirmation dialog (an "active install"), or customize the update experience in any way, refer to the `sync` method's [API reference](#codepushsync) for information on how to tweak this default behavior. | ||
If an update is available, it will be silently downloaded, and installed the next time the app is restarted (either explicitly by the end user or by the OS), which ensures the least invasive experience for your end users. If an available update is mandatory, then it will be installed immediately, ensuring that the end user gets it as soon as possible. | ||
If you would like your app to discover updates more quickly, you can also choose to call `sync` every time the app resumes from the background, by adding the following code (or something equivalent) as part of your app's startup behavior (e.g. your root component's `componentDidMount` method). You can call `sync` as frequently as you would like, so when and where you call it just depends on your personal preference. | ||
```javascript | ||
AppState.addEventListener("change", (newState) => { | ||
newState === "active" && codePush.sync(); | ||
}); | ||
``` | ||
Additionally, if you would like to display an update confirmation dialog (an "active install"), configure when an available update is installed (e.g. force an immediate restart) or customize the update experience in any way, refer to the `sync` method's [API reference](#codepushsync) for information on how to tweak this default behavior. | ||
<a id="apple-note">*NOTE: While [Apple's developer agreement](https://developer.apple.com/programs/ios/information/iOS_Program_Information_4_3_15.pdf) fully allows performing over-the-air updates of JavaScript and assets (which is what enables CodePush!), it is against their policy for an app to display an update prompt. Because of this, we recommend that App Store-distributed apps don't enable the `updateDialog` option when calling `sync`, whereas Google Play and internally distributed apps (e.g. Enterprise, Fabric, HockeyApp) can choose to enable/customize it.*</a> | ||
@@ -319,3 +329,3 @@ | ||
Once your app has been configured and distributed to your users, and you've made some JS and/or asset changes, it's time to instantly release them! The simplest (and recommended) way to do this is to use the `release-react` comand in the CodePush CLI, which will handle bundling your JavaScript and asset files and releasing the update to the CodePush server. | ||
Once your app has been configured and distributed to your users, and you've made some JS and/or asset changes, it's time to instantly release them! The simplest (and recommended) way to do this is to use the `release-react` command in the CodePush CLI, which will handle bundling your JavaScript and asset files and releasing the update to the CodePush server. | ||
@@ -374,4 +384,6 @@ In it's most basic form, this command only requires two parameters: your app name and the platform you are bundling the update for (either `ios` or `android`). | ||
* [getCurrentPackage](#codepushgetcurrentpackage): Retrieves the metadata about the currently installed update (e.g. description, installation time, size). | ||
* [getCurrentPackage](#codepushgetcurrentpackage): Retrieves the metadata about the currently installed update (e.g. description, installation time, size). *NOTE: As of `v1.10.3-beta` of the CodePush module, this method is deprecated in favor of [`getUpdateMetadata`](#codepushgetupdatemetadata)*. | ||
* [getUpdateMetadata](#codepushgetupdatemetadata): Retrieves the metadata for an installed update (e.g. description, mandatory). | ||
* [notifyApplicationReady](#codepushnotifyapplicationready): Notifies the CodePush runtime that an installed update is considered successful. If you are manually checking for and installing updates (i.e. not using the [sync](#codepushsync) method to handle it all for you), then this method **MUST** be called; otherwise CodePush will treat the update as failed and rollback to the previous version when the app next restarts. | ||
@@ -416,2 +428,4 @@ | ||
*NOTE: This method is considered deprecated as of `v1.10.3-beta` of the CodePush module. If you're running this version (or newer), we would recommend using the [`codePush.getUpdateMetadata`](#codepushgetupdatemetadata) instead, since it has more predictable behavior.* | ||
```javascript | ||
@@ -446,12 +460,56 @@ codePush.getCurrentPackage(): Promise<LocalPackage>; | ||
#### codePush.notifyApplicationReady | ||
#### codePush.getUpdateMetadata | ||
```javascript | ||
codePush.notifyApplicationReady(): Promise<void>; | ||
codePush.getUpdateMetadata(updateState: UpdateState = UpdateState.RUNNING): Promise<LocalPackage>; | ||
``` | ||
Retrieves the metadata for an installed update (e.g. description, mandatory) whose state matches the specified `updateState` parameter. This can be useful for scenarios such as displaying a "what's new?" dialog after an update has been applied or checking whether there is a pending update that is waiting to be applied via a resume or restart. For more details about the possible update states, and what they represent, refer to the [UpdateState reference](#updatestate). | ||
This method returns a `Promise` which resolves to one of two possible values: | ||
1. `null` if an update with the specified state doesn't currently exist. This occurs in the following scenarios: | ||
1. The end-user hasn't installed any CodePush updates yet, and therefore, no metadata is available for any updates, regardless what you specify as the `updateState` parameter. | ||
2. The end-user installed an update of the binary (e.g. from the store), which cleared away the old CodePush updates, and gave precedence back to the JS binary in the binary. Therefore, it would exhibit the same behavior as #1 | ||
3. The `updateState` parameter is set to `UpdateState.RUNNING`, but the app isn't currently running a CodePush update. There may be a pending update, but the app hasn't been restarted yet in order to make it active. | ||
4. The `updateState` parameter is set to `UpdateState.PENDING`, but the app doesn't have any currently pending updates. | ||
2. A [`LocalPackage`](#localpackage) instance which represents the metadata for the currently requested CodePush update (either the running or pending). | ||
Example Usage: | ||
```javascript | ||
// Check if there is currently a CodePush update running, and if | ||
// so, register it with the HockeyApp SDK (https://github.com/slowpath/react-native-hockeyapp) | ||
// so that crash reports will correctly display the JS bundle version the user was running. | ||
codePush.getUpdateMetadata().then((update) => { | ||
if (update) { | ||
hockeyApp.addMetadata({ CodePushRelease: update.label }); | ||
} | ||
}); | ||
// Check to see if there is still an update pending. | ||
codePush.getUpdateMetadata(UpdateState.PENDING).then((update) => { | ||
if (update) { | ||
// There's a pending update, do we want to force a restart? | ||
} | ||
}); | ||
``` | ||
#### codePush.notifyAppReady | ||
```javascript | ||
codePush.notifyAppReady(): Promise<void>; | ||
``` | ||
Notifies the CodePush runtime that a freshly installed update should be considered successful, and therefore, an automatic client-side rollback isn't necessary. It is mandatory to call this function somewhere in the code of the updated bundle. Otherwise, when the app next restarts, the CodePush runtime will assume that the installed update has failed and roll back to the previous version. This behavior exists to help ensure that your end users aren't blocked by a broken update. | ||
If you are using the `sync` function, and doing your update check on app start, then you don't need to manually call `notifyApplicationReady` since `sync` will call it for you. This behavior exists due to the assumption that the point at which `sync` is called in your app represents a good approximation of a successful startup. | ||
If you are using the `sync` function, and doing your update check on app start, then you don't need to manually call `notifyAppReady` since `sync` will call it for you. This behavior exists due to the assumption that the point at which `sync` is called in your app represents a good approximation of a successful startup. | ||
*NOTE: This method is also aliased as `notifyApplicationReady` (for backwards compatibility).* | ||
#### codePush.restartApp | ||
@@ -485,3 +543,2 @@ | ||
Example Usage: | ||
@@ -604,3 +661,3 @@ | ||
The `checkForUpdate` and `getCurrentPackage` methods return promises, that when resolved, provide acces to "package" objects. The package represents your code update as well as any extra metadata (e.g. description, mandatory?). The CodePush API has the distinction between the following types of packages: | ||
The `checkForUpdate` and `getUpdateMetadata` methods return `Promise` objects, that when resolved, provide acces to "package" objects. The package represents your code update as well as any extra metadata (e.g. description, mandatory?). The CodePush API has the distinction between the following types of packages: | ||
@@ -613,3 +670,3 @@ * [LocalPackage](#localpackage): Represents a downloaded update that is either already running, or has been installed and is pending an app restart. | ||
Contains details about an update that has been downloaded locally or already installed. You can get a reference to an instance of this object either by calling the module-level `getCurrentPackage` method, or as the value of the promise returned by the `RemotePackage.download` method. | ||
Contains details about an update that has been downloaded locally or already installed. You can get a reference to an instance of this object either by calling the module-level `getUpdateMetadata` method, or as the value of the promise returned by the `RemotePackage.download` method. | ||
@@ -652,3 +709,3 @@ ###### Properties | ||
This enum specified when you would like an installed update to actually be applied, and can be passed to either the `sync` or `LocalPackage.install` methods. It includes the following values: | ||
This enum specifies when you would like an installed update to actually be applied, and can be passed to either the `sync` or `LocalPackage.install` methods. It includes the following values: | ||
@@ -675,2 +732,12 @@ * __codePush.InstallMode.IMMEDIATE__ *(0)* - Indicates that you want to install the update and restart the app immediately. This value is appropriate for debugging scenarios as well as when displaying an update prompt to the user, since they would expect to see the changes immediately after accepting the installation. Additionally, this mode can be used to enforce mandatory updates, since it removes the potentially undesired latency between the update installation and the next time the end user restarts or resumes the app. | ||
##### UpdateState | ||
This enum specifies the state that an update is currently in, and can be specified when calling the `getUpdateMetadata` method. It includes the following values: | ||
* __codePush.UpdateState.RUNNING__ *(0)* - Indicates that an update represents the version of the app that is currently running. This can be useful for identifying attributes about the app, for scenarios such as displaying the release description in a "what's new?" dialog or reporting the latest version to an analytics and/or crash reporting service. | ||
* __codePush.UpdateState.PENDING__ *(1)* - Indicates than an update has been installed, but the app hasn't been restarted yet in order to apply it. This can be useful for determining whether there is a pending update, which you may want to force a programmatic restart (via `restartApp`) in order to apply. | ||
* __codePush.UpdateState.LATEST__ *(2)* - Indicates than an update represents the latest available release, and can be either currently running or pending. | ||
### Objective-C API Reference (iOS) | ||
@@ -677,0 +744,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
758529
87
2555
825