You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on May 20, 2025. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+38-10Lines changed: 38 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,6 +25,8 @@ A React Native app is composed of JavaScript files and any accompanying [images]
25
25
26
26
The CodePush plugin helps get product improvements in front of your end users instantly, by keeping your JavaScript and images synchronized with updates you release to the CodePush server. This way, your app gets the benefits of an offline mobile experience, as well as the "web-like" agility of side-loading updates as soon as they are available. It's a win-win!
27
27
28
+
In order to ensure that your end users always have a functioning version of your app, the CodePush plugin maintains a copy of the previous update, so that in the event that you accidentally push an update which includes a crash, it can automatically roll back to the "last known good". This way, you can rest assured that your newfound release agility can't result in any users becoming blocked by a bad update, before you have a chance to [roll it back](http://microsoft.github.io/code-push/docs/cli.html#link-8) on the server. It's a win-win-win!
29
+
28
30
*Note: Any product changes which touch native code (e.g. modifying your `AppDelegate.m`/`MainActivity.java` file, adding a new plugin) cannot be distributed via CodePush, and therefore, must be updated via the appropriate store(s).*
29
31
30
32
## Supported React Native platforms
@@ -192,7 +194,7 @@ The simplest way to do this is to perform the following in your app's root compo
192
194
1. Import the JavaScript module for CodePush:
193
195
194
196
```
195
-
var CodePush = require("react-native-code-push")
197
+
import CodePush from "react-native-code-push";
196
198
```
197
199
198
200
2. Call the `sync` method from within the `componentDidMount` lifecycle event, to initiate a background update on each app start:
@@ -283,8 +285,13 @@ Queries the CodePush service to see whether the configured app deployment has an
283
285
284
286
This method returns a `Promise` which resolves to one of two possible values:
285
287
286
-
*`null` if there is no update available.
287
-
* A `RemotePackage` instance which represents an available update that can be inspected and/or subsequently downloaded.
288
+
1.`null` if there is no update available. This occurs in the following scenarios:
289
+
290
+
1. The configured deployment doesn't contain any releases, and therefore, nothing to update.
291
+
2. The latest release within the configured deployment is targeting a different binary version than what you're currently running (either older or newer).
292
+
3. The currently running app already has the latest release from the configured deployment, and therefore, doesn't need it again.
293
+
294
+
2. A [`RemotePackage`](#remotepackage) instance which represents an available update that can be inspected and/or subsequently downloaded.
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.
315
+
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.
309
316
310
-
This method returns a `Promise` which resolves to the `LocalPackage` instance that represents the currently running update.
317
+
This method returns a `Promise` which resolves to the [`LocalPackage`](#localpackage) instance that represents the currently running update.
311
318
312
319
Example Usage:
313
320
@@ -353,11 +360,11 @@ This method is for advanced scenarios, and is primarily useful when the followin
Synchronizes your app's JavaScript bundle and image assets 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.
363
+
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.
357
364
358
365
This method provides support for two different (but customizable) "modes" to easily enable apps with different requirements:
359
366
360
-
1. **Silent mode** *(the default behavior)*, which automatically downloads available updates, and applies them the next time the app restarts. This way, the entire update experience is "silent" to the end user, since they don't see any update prompt and/or "synthetic" app restarts.
367
+
1. **Silent mode** *(the default behavior)*, which automatically downloads available updates, and applies them the next time the app restarts (e.g. the OS or end user killed it, or the device was restarted). This way, the entire update experience is "silent" to the end user, since they don't see any update prompt and/or "synthetic" app restarts.
361
368
362
369
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.
codePush.sync({ updateDialog: { title:"An update is available!" } });
427
+
428
+
// Displaying an update prompt which includes the
429
+
// description associated with the CodePush release
430
+
codePush.sync({
431
+
updateDialog: {
432
+
appendReleaseDescription:true,
433
+
descriptionPrefix:"\n\nChange log:\n"
434
+
},
435
+
installMode:codePush.InstallMode.IMMEDIATE
436
+
});
437
+
438
+
420
439
```
421
440
422
441
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):
This method returns a `Promise` which is resolved to a `SyncStatus` code that indicates why the `sync` call succeeded. This code can be one of the following `SyncStatus` values:
448
467
449
468
*__CodePush.SyncStatus.UP_TO_DATE__*(4)* - The app is up-to-date with the CodePush server.
469
+
450
470
*__CodePush.SyncStatus.UPDATE_IGNORED__*(5)* - The app had an optional update which the end user chose to ignore. (This is only applicable when the `updateDialog` is used)
471
+
451
472
*__CodePush.SyncStatus.UPDATE_INSTALLED__*(6)* - The update has been installed and will be run either immediately after the `syncStatusChangedCallback` function returns or the next time the app resumes/restarts, depending on the `InstallMode` specified in `SyncOptions`.
452
473
453
474
If the update check and/or the subsequent download fails for any reason, the `Promise` object returned by `sync` will be rejected with the reason.
@@ -458,7 +479,8 @@ The `sync` method can be called anywhere you'd like to check for an update. That
458
479
459
480
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:
460
481
461
-
*[LocalPackage](#localpackage): Represents a downloaded update package that is either already running, or has been installed and is pending an app restart.
482
+
*[LocalPackage](#localpackage): Represents a downloaded update that is either already running, or has been installed and is pending an app restart.
483
+
462
484
*[RemotePackage](#remotepackage): Represents an available update on the CodePush server that hasn't been downloaded yet.
463
485
464
486
##### LocalPackage
@@ -557,10 +579,16 @@ Constructs the CodePush client runtime and includes methods for integrating Code
557
579
558
580
##### Constructors
559
581
560
-
-__CodePush(String deploymentKey, Activity mainActivity)__ - Creates a new instance of the CodePush runtime, that will be used to query the service for updates via the provided deployment key. The `mainActivity` parameter should always be set to `this` when configuring your `ReactInstanceManager` inside the `MainActivity` class.
582
+
-__CodePush(String deploymentKey, Activity mainActivity)__ - Creates a new instance of the CodePush runtime, that will be used to query the service for updates via the provided deployment key. The `mainActivity` parameter should always be set to `this` when configuring your `ReactInstanceManager` inside the `MainActivity` class. This constructor puts the CodePush runtime into "release mode", so if you want to enable debugging behavior, use the following constructor instead.
561
583
584
+
-__CodePush(String deploymentKey, Activity mainActivity, bool isDebugMode)__ - Equivalent to the previous constructor, but allows you to specify whether you want the CodePush runtime to be in debug mode or not. When using this constructor, the `isDebugMode` parameter should always be set to `BuildConfig.DEBUG` in order to stay synchronized with your build type. When putting CodePush into debug mode, the following behaviors are enabled:
585
+
586
+
1. Old CodePush updates aren't deleted from storage whenever a new binary is deployed to the emulator/device. This behavior enables you to deploy new binaries, without bumping the version during development, and without continuously getting the same update every time your app calls `sync`.
587
+
588
+
2. The local cache that the React Native runtime maintains in debug mode is deleted whenever a CodePush update is installed. This ensures that when the app is restarted after an update is applied, you will see the expected changes. As soon as [this PR](https://github.com/facebook/react-native/pull/4738) is merged, we won't need to do this anymore.
589
+
562
590
##### Methods
563
591
564
592
-__getBundleUrl(String bundleName)__ - Returns the path to the most recent version of your app's JS bundle file, using the specified resource name (e.g. `index.android.bundle`). This method has the same resolution behavior as the Objective-C equivalent described above.
565
593
566
-
-__getReactPackage()__ - Returns a `ReactPackage` object that should be added to your `ReactInstanceManager` via its `addPackage` method. Without this, the `react-native-code-push` JS module won't be available to your script.
594
+
-__getReactPackage()__ - Returns a `ReactPackage` object that should be added to your `ReactInstanceManager` via its `addPackage` method. Without this, the `react-native-code-push` JS module won't be available to your script.
0 commit comments