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
+35-25Lines changed: 35 additions & 25 deletions
Original file line number
Diff line number
Diff line change
@@ -4,8 +4,8 @@ This plugin provides client-side integration for the [CodePush service](https://
4
4
5
5
The CodePush React Native API provides two primary mechanisms for discovering updates and dynamically applying them within your apps:
6
6
7
-
1.**Sync mode**, which allows you to call a single method--presumably as part of mounting your app's root component or in response to a button click--that will automatically check for an update, download and apply it, while respecting the policies and metadata associated with each release (e.g. if the release is mandatory then it doesn't give the end-user the option to ignore it)
8
-
2.**Advanced mode**, which provides a handful of "low-level" methods which give you complete control over the update experience, at the cost of added complexity.
7
+
1.[**Sync mode**](#codePushssync), which allows you to call a single method--presumably as part of mounting your app's root component or in response to a button click--that will automatically check for an update, download and apply it, while respecting the policies and metadata associated with each release (e.g. if the release is mandatory then it doesn't give the end-user the option to ignore it)
8
+
2.[**Advanced mode**](#codepushcheckforupdate), which provides a handful of "low-level" methods which give you complete control over the update experience, at the cost of added complexity.
9
9
10
10
When getting started using CodePush, we would recommended using the sync mode until you discover that it doesn't suit your needs. That said, if you have a user scenario
11
11
that isn't currently covered well by sync, please [let us know](mailto:codepushfeed@microsoft.com) since that would be valuable feedback.
@@ -80,7 +80,6 @@ To let the CodePush runtime know which deployment it should query for updates ag
80
80
1. Open your app's `Info.plist` and add a new `CodePushDeploymentKey` entry, whose value is the key of the deployment you want to configure this app against (e.g. the Staging deployment for FooBar app)
81
81
2. In your app's `Info.plist` make sure your `CFBundleShortVersionString` value is a valid [semver](http://semver.org/) version (e.g. 1.0.0 not 1.0)
82
82
83
-
84
83
## Plugin consumption
85
84
86
85
With the CodePush plugin downloaded and linked, and your app asking CodePush where to get the right JS bundle from, the only thing left is to add the neccessary code to your app to control the following:
@@ -102,8 +101,8 @@ The simplest way to do this is to perform the following in your app's root compo
102
101
CodePush.sync();
103
102
```
104
103
105
-
If an update is available, a dialog will be display to the user asking them if they would like to install it. If the update was marked as mandatory, then the dialog will
106
-
omit the option to decline installation.
104
+
If an update is available, a dialog will be displayed to the user asking them if they would like to install it. If the update was marked as mandatory, then the dialog will
105
+
omit the option to decline installation. The `sync` method takes a handful of options to customize this experience, so refer to its [API reference](#codePushsync) if you'd like to tweak its default behavior.
107
106
108
107
## Releasing code updates
109
108
@@ -128,12 +127,13 @@ When you require the `react-native-code-push` module, that object provides the f
128
127
* [sync](#codepushsync): Allows checking for an update, downloading it and applying it, all with a single call. Unless you need custom UI and/or behavior, we recommend most developers to use this method when integrating CodePush into their apps
129
128
130
129
#### codePush.checkForUpdate
131
-
Queries the CodePush service for an update against the configured deployment. This method returns a promise which resolves to a `RemotePackage` that can be subsequently downloaded.
Queries the CodePush service for an update against the configured deployment. This method returns a promise which resolves to a `RemotePackage` that can be subsequently downloaded.
136
+
137
137
`checkForUpdate` returns a Promise that resolves to one of two values:
Gets information about the currently applied package (e.g. description, installation time).
162
+
162
163
This method returns a Promise that resolves with the `LocalPackage` instance that represents the running update. This API is only useful for advanced scenarios, and so many devs won't need to concern themselves with it.
163
164
164
165
#### codePush.notifyApplicationReady
165
166
167
+
```javascript
168
+
codePush.notifyApplicationReady():Promise<void>;
169
+
```
170
+
166
171
Notifies the CodePush runtime that an update is considered successful, and therefore, a rollback isn't neccessary. Calling this function is required whenever the `rollbackTimeout` parameter is specified when calling either ```LocalPackage.apply``` or `sync`. If you specify a `rollbackTimeout`, and don't call `notifyApplicationReady`, the CodePush runtime will assume that the applied update has failed and roll back to the previous version.
167
172
168
173
If the `rollbackTimeout` parameter was not specified, the CodePush runtime will not enforce any automatic rollback behavior, and therefore, calling this function is not required and will result in a no-op.
169
174
175
+
#### codePush.sync
176
+
170
177
```javascript
171
-
codePush.notifyApplicationReady():Promise<void>;
178
+
codePush.sync(options:Object):Promise<Number>;
172
179
```
173
180
174
-
#### codePush.sync
175
-
176
-
Provides a simple option for checking for an update, downloading it and then applying it, all while also respecting the policy that your release was published with. This method effectively composes together the "advanced mode" APIs for you, so that you don't need to handle any of the following scenarios yourself:
181
+
Provides a simple option for checking for an update, displaying a notification to the user, downloading it and then applying it, all while also respecting the policy that your release was published with. This method effectively composes together the "advanced mode" APIs for you, so that you don't need to handle any of the following scenarios yourself:
177
182
178
183
1. Checking for an update and displaying a standard confirmation dialog asking if they would like to install it
179
184
2. Automatically ignoring updates which have previously failed to apply (due to automatic rollback), and therefore, likely don't make sense trying to apply again (let's blacklist them!)
180
185
3. Looking to see whether an available update is mandatory, and if so, don't give the end-user the choice to ignore it
181
186
4. Displaying the description of an update to the end-user as part of the install confirmation experience
182
187
183
188
If you want to pivot whether you check and/or download an available update based on the end-user's device battery level, network conditions, etc. then simply wrap the call to `sync` in a condition that ensures you only call it when desired.
184
-
```javascript
185
-
codePush.sync(options:Object):Promise<Boolean>
186
-
```
187
189
188
-
The method accepts an options object that allows you to customize numerous aspects of the default behavior, all of which provide sensible defaults by default:
190
+
The method accepts an options object that allows you to customize numerous aspects of the default behavior, all of which provide sensible values by default:
189
191
190
192
*__appendReleaseDescription__ (Boolean) - Indicates whether you would like to append the description of an available release to the notification message which is displayed to the end-user. Defaults to `false`.
191
193
*__descriptionPrefix__ (String) - Indicates the string you would like to prefix the release description with, if any, when displaying the update notification to the end-user. Defaults to `" Description: "`
@@ -198,23 +200,31 @@ The method accepts an options object that allows you to customize numerous aspec
198
200
*__rollbackTimeout__ (String) - The number of seconds that you want the runtime to wait after an update has been applied before considering it failed and rolling it back. Defaults to `0`, which disabled rollback protection.
199
201
*__updateTitle__ (String) - The text used as the header of an update notification that is displayed to the end-user. Defaults to `"Update available"`.
200
202
201
-
The method returns a Promise that is resolved to a `SyncStatus` code, which indicates why the `sync` call succeeded. This code can be one of the following values:
203
+
The method returns a `Promise` that is resolved to a `SyncStatus` integer code, which indicates why the `sync` call succeeded. This code can be one of the following values:
202
204
203
205
*__CodePush.SyncStatus.UP_TO_DATE__*(0)* - The app doesn't have an available update.
204
206
*__CodePush.SyncStatus.UPDATE_IGNORED__*(1)* - The app has an optional update, that the user chose to ignore.
205
207
*__CodePush.SyncStatus.UPDATE_APPLIED__*(2)* - The app had an optional or mandatory update that was successfully downloaded and is about to be applied. If your app needs to do any data persistence/migration before restarting, this is the time to do it.
206
208
209
+
If the update check and/or the subseqeuent download fails for any reason, the `Promise` object returned by `sync` will be rejected with the reason.
210
+
207
211
Example Usage:
208
212
209
213
```javascript
210
-
codePush.sync().then((status) => {
211
-
if (status ==codePush.SyncStatus.UPDATE_APPLIED) {
212
-
// Do any neccessary work here before the app
213
-
// is restarted in order to apply the update
214
-
}
215
-
});
216
-
214
+
codePush.sync()
215
+
.then((status) => {
216
+
if (status ==codePush.SyncStatus.UPDATE_APPLIED) {
217
+
// Do any neccessary work here before the app
218
+
// is restarted in order to apply the update
219
+
}
220
+
})
221
+
.catch((reason) => {
222
+
// Do something with the failure
223
+
});
217
224
```
225
+
226
+
The `sync` method can be called anywhere you'd like to check for an update. That could be in the `componentWillMount` lifecycle event of your root component, the onPress handler of a `<TouchableHighlight>` component, in the callback of a periodic timer, or whatever else makes sense for your needs. Just like the `checkForUpdate` method, it will perform the network request to check for an update in the background, so it won't impact your UI thread and/or JavaScript thread's responsiveness.
227
+
218
228
### Package objects
219
229
220
230
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:
@@ -273,4 +283,4 @@ The `RemotePackage` inherits all of the same properties as the `LocalPackage`, b
273
283
* Open `CodePushDemoApp.xcodeproj` in Xcode
274
284
* Navigate to the test explorer (small grey diamond near top left)
275
285
* Click on the 'play' button next to CodePushDemoAppTests
276
-
* After the tests are completed, green ticks should appear next to the test cases to indicate success
286
+
* After the tests are completed, green ticks should appear next to the test cases to indicate success
0 commit comments