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

Commit c6dd347

Browse files
author
Will Anderson
committed
Merge pull request #8 from Microsoft/code-push-docs
Initial pass at RN Code Push documentation
2 parents 38fbf64 + 6ea93dd commit c6dd347

File tree

1 file changed

+134
-6
lines changed

1 file changed

+134
-6
lines changed

README.md

Lines changed: 134 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,81 @@
1-
code-push-react-native
1+
react-native-code-push
22
===
33

4-
React Native module for deploying script updates
4+
React Native module for deploying script updates using the CodePush service.
5+
6+
Installation
7+
---
8+
9+
```
10+
npm install --save react-native-code-push
11+
```
12+
13+
After installing the React Native CodePush plugin, open your project in Xcode. Open the `react-native-code-push` in Finder, and drag the `CodePush.xcodeproj` into the Libraries folder of Xcode.
14+
15+
![Add CodePush to project](https://cloud.githubusercontent.com/assets/516559/10322414/7688748e-6c32-11e5-83c1-00d3e6758df4.png)
16+
17+
18+
In Xcode, click on your project, and select the "Build Phases" tab of your project configuration. Drag libCodePush.a from `Libraries/CodePush.xcodeproj/Products` into the "Link Binary With Libraries" secton of your project's "Build Phases" configuration.
19+
20+
![Link CodePush during build](https://cloud.githubusercontent.com/assets/516559/10322221/a75ea066-6c31-11e5-9d88-ff6f6a4d6968.png)
21+
22+
Under the "Build Settings" tab of your project configuration, find the "Header Search Paths" section and edit the value.
23+
Add a new value, `$(SRCROOT)/../node_modules/react-native-code-push` and select "recursive" in the dropdown.
24+
25+
![Add CodePush library reference](https://cloud.githubusercontent.com/assets/516559/10322038/b8157962-6c30-11e5-9264-494d65fd2626.png)
26+
27+
Finally, edit your project's `AppDelegate.m`.
28+
29+
At the top of the file, add the following line to import the CodePush headers.
30+
31+
```
32+
#import "CodePush.h"
33+
```
34+
35+
Then, find the following code:
36+
37+
```
38+
jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.bundle?platform=ios&dev=true"];
39+
```
40+
41+
Replace it with this:
42+
43+
```
44+
jsCodeLocation = [CodePush getBundleUrl];
45+
```
46+
47+
This change allows CodePush to load the updated app location after an update has been applied.
48+
Before any updates are installed, CodePush will load your app from the bundled "main.jsbundle" file.
49+
After updates are installed, CodePush will load your app from the writable user directory, where the update has been downloaded.
50+
51+
Methods
52+
---
53+
54+
* [checkForUpdate](#codepushcheckforupdate): Checks the service for updates
55+
* [notifyApplicationReady](#codepushnotifyapplicationready): Notifies the plugin that the update operation succeeded.
56+
* [getCurrentPackage](#codepushgetcurrentpackage): Gets information about the currently applied package.
57+
58+
Objects
59+
---
60+
61+
* [LocalPackage](#localpackage): Contains information about a locally installed package.
62+
* [RemotePackage](#remotepackage): Contains information about an updated package available for download.
63+
64+
Getting Started:
65+
---
66+
67+
* Add the plugin to your app
68+
* Open your app's `Info.plist` and add a "CodePushDeploymentKey" entry with your app's deployment key
69+
* To publish an update for your app, run `react-native bundle`, and then publish `iOS/main.jsbundle` using the CodePush CLI.
570

671
Running the Example
772
---
873

9-
* Make sure you have https://github.com/Microsoft/hybrid-mobile-deploy cloned beside the react-native project in a folder called `website`. This is hacky, and will be cleaned up as soon as React Native's packager supports symlinks.
10-
* Start the CodePush server with `gulp serve`, after installing the prerequisites described in the [project readme](https://github.com/Microsoft/hybrid-mobile-deploy/blob/master/README.md)
74+
* Clone this repository
1175
* From the root of this project, run `npm install`
1276
* `cd` into `Examples/CodePushDemoApp`
1377
* From this demo app folder, run `npm install`
14-
* Open `Info.plist` and fill in the values for CodePushDeploymentKey and CodePushServerUrl
78+
* Open `Info.plist` and fill in the value for CodePushDeploymentKey
1579
* Run `npm start` to launch the packager
1680
* Open `CodePushDemoApp.xcodeproj` in Xcode
1781
* Launch the project
@@ -22,4 +86,68 @@ Running Tests
2286
* Open `CodePushDemoApp.xcodeproj` in Xcode
2387
* Navigate to the test explorer (small grey diamond near top left)
2488
* Click on the 'play' button next to CodePushDemoAppTests
25-
* After the tests are completed, green ticks should appear next to the test cases to indicate success
89+
* After the tests are completed, green ticks should appear next to the test cases to indicate success
90+
91+
92+
## LocalPackage
93+
Contains details about an update package that has been downloaded locally or already applied (currently installed package).
94+
### Properties
95+
- __deploymentKey__: Deployment key of the package. (String)
96+
- __description__: Package description. (String)
97+
- __label__: Package label. (String)
98+
- __appVersion__: The native version of the application this package update is intended for. (String)
99+
- __isMandatory__: Flag indicating if the update is mandatory. (Boolean)
100+
- __packageHash__: The hash value of the package. (String)
101+
- __packageSize__: The size of the package, in bytes. (Number)
102+
103+
### Methods
104+
- __apply(rollbackTimeout): Promise__: Applies this package to the application. The application will be reloaded with this package and on every application launch this package will be loaded.
105+
If the rollbackTimeout parameter is provided, the application will wait for a codePush.notifyApplicationReady() for the given number of milliseconds.
106+
If codePush.notifyApplicationReady() is called before the time period specified by rollbackTimeout, the apply operation is considered a success.
107+
Otherwise, the apply operation will be marked as failed, and the application is reverted to its previous version.
108+
109+
## RemotePackage
110+
Contains details about an update package that is available for download.
111+
### Properties
112+
- __deploymentKey__: Deployment key of the package. (String)
113+
- __description__: Package description. (String)
114+
- __label__: Package label. (String)
115+
- __appVersion__: The native version of the application this package update is intended for. (String)
116+
- __isMandatory__: Flag indicating if the update is mandatory. (Boolean)
117+
- __packageHash__: The hash value of the package. (String)
118+
- __packageSize__: The size of the package, in bytes. (Number)
119+
- __downloadUrl__: The URL at which the package is available for download. (String)
120+
121+
### Methods
122+
- __download(): Promise<LocalPackage>__: Downloads the package update from the CodePush service. Returns a Promise that resolves with the LocalPackage.
123+
124+
## codePush.checkForUpdate
125+
Queries the CodePush server for updates.
126+
```javascript
127+
codePush.checkForUpdate(): Promise<RemotePackage>;
128+
```
129+
130+
`checkForUpdate` returns a Promise that resolves when the server responds with an update.
131+
132+
133+
Usage:
134+
```javascript
135+
codePush.checkForUpdate().then((update) => {
136+
console.log(update);
137+
});
138+
```
139+
140+
## codePush.getCurrentPackage
141+
```javascript
142+
codePush.getCurrentPackage(): Promise<LocalPackage>;
143+
```
144+
Get the currently installed package information. Returns a Promise that resolves with the local package.
145+
146+
## codePush.notifyApplicationReady
147+
```javascript
148+
codePush.notifyApplicationReady(): Promise<void>;
149+
```
150+
151+
Notifies the plugin that the update operation succeeded.
152+
Calling this function is required if a rollbackTimeout parameter is passed to your ```LocalPackage.apply``` call.
153+
If automatic rollback was not used, calling this function is not required and will result in a noop.

0 commit comments

Comments
 (0)