Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit a3bd17a

Browse files
committed
Doc and .d.ts updates
1 parent 303edd1 commit a3bd17a

File tree

2 files changed

+65
-20
lines changed

2 files changed

+65
-20
lines changed

README.md

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ When you require `react-native-code-push`, the module object provides the follow
378378

379379
* [checkForUpdate](#codepushcheckforupdate): Asks the CodePush service whether the configured app deployment has an update available.
380380

381-
* [getCurrentPackage](#codepushgetcurrentpackage): Retrieves the metadata about the currently installed update (e.g. description, installation time, size).
381+
* [getUpdateMetadata](#codepushgetupdatemetadata): Retrieves the metadata for an installed update (e.g. description, mandatory).
382382

383383
* [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.
384384

@@ -417,33 +417,41 @@ codePush.checkForUpdate()
417417
});
418418
```
419419

420-
#### codePush.getCurrentPackage
420+
#### codePush.getUpdateMetadata
421421

422422
```javascript
423-
codePush.getCurrentPackage(): Promise<LocalPackage>;
423+
codePush.getUpdateMetadata(updateState: UpdateState = UpdateState.RUNNING): Promise<LocalPackage>;
424424
```
425425

426-
Retrieves the metadata about the currently installed "package" (e.g. description, installation time). 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.
426+
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).
427427

428428
This method returns a `Promise` which resolves to one of two possible values:
429429

430-
1. `null` if the app is currently running the JS bundle from the binary and not a CodePush update. This occurs in the following scenarios:
430+
1. `null` if an update with the specified state doesn't currently exist. This occurs in the following scenarios:
431431

432-
1. The end-user installed the app binary and has yet to install a CodePush update
432+
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.
433433
1. 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.
434+
1. The `updateState` parameter is set to `UpdateState.RUNNING`, but the app isn't currently running a CodePush update. There may be a pending update, which requires an app restart to become active.
435+
1. The `updateState` parameter is set to `UpdateState.PENDING`, but the app doesn't have any pending updates.
434436

435-
2. A [`LocalPackage`](#localpackage) instance which represents the metadata for the currently running CodePush update.
437+
2. A [`LocalPackage`](#localpackage) instance which represents the metadata for the currently requested CodePush update (either the running or pending).
436438

437439
Example Usage:
438440

439441
```javascript
440-
codePush.getCurrentPackage()
441-
.then((update) => {
442-
// If the current app "session" represents the first time
443-
// this update has run, and it had a description provided
444-
// with it upon release, let's show it to the end user
445-
if (update.isFirstRun && update.description) {
446-
// Display a "what's new?" modal
442+
// Check if there is currently a CodePush update running, and if
443+
// so, register it with the HockeyApp SDK (https://github.com/slowpath/react-native-hockeyapp)
444+
// so that crash reports will correctly display the JS bundle version the user was running.
445+
codePush.getUpdateMetadata().then((update) => {
446+
if (update) {
447+
hockeyApp.addMetadata({ CodePushRelease: update.label });
448+
}
449+
});
450+
451+
// Check to see if there is still an update pending.
452+
codePush.getUpdateMetadata(UpdateState.PENDING).then((update) => {
453+
if (update) {
454+
// There's a pending update, do we want to force a restart?
447455
}
448456
});
449457
```
@@ -486,7 +494,6 @@ This method provides support for two different (but customizable) "modes" to eas
486494

487495
2. **Active mode**, which when an update is available, prompts the end user for permission before downloading it, and then immediately applies the update. If an update was released using the `mandatory` flag, the end user would still be notified about the update, but they wouldn't have the choice to ignore it.
488496

489-
490497
Example Usage:
491498

492499
```javascript
@@ -650,7 +657,7 @@ The CodePush API includes the following enums which can be used to customize the
650657
651658
##### InstallMode
652659
653-
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:
660+
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:
654661
655662
* __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.
656663
@@ -672,6 +679,16 @@ This enum is provided to the `syncStatusChangedCallback` function that can be pa
672679
* __codePush.SyncStatus.SYNC_IN_PROGRESS__ *(7)* - There is an ongoing `sync` operation running which prevents the current call from being executed.
673680
* __codePush.SyncStatus.UNKNOWN_ERROR__ *(-1)* - The sync operation encountered an unknown error.
674681
682+
##### UpdateState
683+
684+
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:
685+
686+
* __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.
687+
688+
* __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.
689+
690+
* __codePush.UpdateState.LATEST__ *(2)* - Indicates than an update represents the latest available release, and can be either currently running or pending.
691+
675692
### Objective-C API Reference (iOS)
676693
677694
The Objective-C API is made available by importing the `CodePush.h` header into your `AppDelegate.m` file, and consists of a single public class named `CodePush`.

react-native-code-push.d.ts

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,13 @@ declare namespace CodePush {
193193
* @param deploymentKey The deployment key to use to query the CodePush server for an update.
194194
*/
195195
function checkForUpdate(deploymentKey?: string): ReactNativePromise<RemotePackage>;
196-
196+
197197
/**
198-
* Retrieves the metadata about the currently installed update (e.g. description, installation time, size).
198+
* Retrieves the metadata for an installed update (e.g. description, mandatory).
199+
*
200+
* @param updateState The state of the update you want to retrieve the metadata for. Defaults to UpdateState.RUNNING.
199201
*/
200-
function getCurrentPackage(): ReactNativePromise<LocalPackage>;
202+
function getUpdateMetadata(updateState?: UpdateState) : ReactNativePromise<LocalPackage>;
201203

202204
/**
203205
* Notifies the CodePush runtime that an installed update is considered successful.
@@ -218,7 +220,7 @@ declare namespace CodePush {
218220
* @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.
219221
* @param downloadProgressCallback An optional callback that allows tracking the progress of an update while it is being downloaded.
220222
*/
221-
function sync(options?: SyncOptions, syncStatusChangedCallback?: SyncStatusChangedCallback, downloadProgressCallback?: DowloadProgressCallback): __React.Promise<SyncStatus>;
223+
function sync(options?: SyncOptions, syncStatusChangedCallback?: SyncStatusChangedCallback, downloadProgressCallback?: DowloadProgressCallback): ReactNativePromise<SyncStatus>;
222224

223225
/**
224226
* Indicates when you would like an installed update to actually be applied.
@@ -241,6 +243,9 @@ declare namespace CodePush {
241243
ON_NEXT_RESUME
242244
}
243245

246+
/**
247+
* Indicates the current status of a sync operation.
248+
*/
244249
enum SyncStatus {
245250
/**
246251
* The CodePush server is being queried for an update.
@@ -291,6 +296,29 @@ declare namespace CodePush {
291296
*/
292297
UNKNOWN_ERROR
293298
}
299+
300+
/**
301+
* Indicates the state that an update is currently in.
302+
*/
303+
enum UpdateState {
304+
/**
305+
* Indicates that an update represents the
306+
* version of the app that is currently running.
307+
*/
308+
RUNNING,
309+
310+
/**
311+
* Indicates than an update has been installed, but the
312+
* app hasn't been restarted yet in order to apply it.
313+
*/
314+
PENDING,
315+
316+
/**
317+
* Indicates than an update represents the latest available
318+
* release, and can be either currently running or pending.
319+
*/
320+
LATEST
321+
}
294322
}
295323

296324
declare module "react-native-code-push" {

0 commit comments

Comments
 (0)