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

Commit 661adce

Browse files
committed
Merge pull request #24 from Microsoft/readme_tweaks
Adding a little more detail to sync and fixing some typos
2 parents 21bd14a + ed92d02 commit 661adce

File tree

1 file changed

+35
-25
lines changed

1 file changed

+35
-25
lines changed

README.md

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ This plugin provides client-side integration for the [CodePush service](https://
44

55
The CodePush React Native API provides two primary mechanisms for discovering updates and dynamically applying them within your apps:
66

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.
99

1010
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
1111
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
8080
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)
8181
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)
8282
83-
8483
## Plugin consumption
8584
8685
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
102101
CodePush.sync();
103102
```
104103
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.
107106
108107
## Releasing code updates
109108
@@ -128,12 +127,13 @@ When you require the `react-native-code-push` module, that object provides the f
128127
* [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
129128
130129
#### 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.
132130
133131
```javascript
134132
codePush.checkForUpdate(): Promise<RemotePackage>;
135133
```
136134

135+
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+
137137
`checkForUpdate` returns a Promise that resolves to one of two values:
138138

139139
* `null` if there is no update available
@@ -154,38 +154,40 @@ codePush.checkForUpdate().then((update) => {
154154

155155
#### codePush.getCurrentPackage
156156

157-
Gets information about the currently applied package (e.g. description, installation time).
158-
159157
```javascript
160158
codePush.getCurrentPackage(): Promise<LocalPackage>;
161159
```
160+
161+
Gets information about the currently applied package (e.g. description, installation time).
162+
162163
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.
163164

164165
#### codePush.notifyApplicationReady
165166

167+
```javascript
168+
codePush.notifyApplicationReady(): Promise<void>;
169+
```
170+
166171
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.
167172

168173
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.
169174

175+
#### codePush.sync
176+
170177
```javascript
171-
codePush.notifyApplicationReady(): Promise<void>;
178+
codePush.sync(options: Object): Promise<Number>;
172179
```
173180

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:
177182

178183
1. Checking for an update and displaying a standard confirmation dialog asking if they would like to install it
179184
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!)
180185
3. Looking to see whether an available update is mandatory, and if so, don't give the end-user the choice to ignore it
181186
4. Displaying the description of an update to the end-user as part of the install confirmation experience
182187

183188
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-
```
187189

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:
189191

190192
* __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`.
191193
* __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
198200
* __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.
199201
* __updateTitle__ (String) - The text used as the header of an update notification that is displayed to the end-user. Defaults to `"Update available"`.
200202

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:
202204

203205
* __CodePush.SyncStatus.UP_TO_DATE__ *(0)* - The app doesn't have an available update.
204206
* __CodePush.SyncStatus.UPDATE_IGNORED__ *(1)* - The app has an optional update, that the user chose to ignore.
205207
* __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.
206208

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+
207211
Example Usage:
208212

209213
```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+
});
217224
```
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+
218228
### Package objects
219229

220230
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
273283
* Open `CodePushDemoApp.xcodeproj` in Xcode
274284
* Navigate to the test explorer (small grey diamond near top left)
275285
* 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

Comments
 (0)