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

Commit bc8d8ad

Browse files
committed
Merge pull request #151 from Microsoft/debug_docs
Adding iOS debug detail
2 parents 8336ab7 + ab07913 commit bc8d8ad

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

README.md

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ In order to ensure that your end users always have a functioning version of your
4040

4141
Once you've followed the general-purpose ["getting started"](http://codepush.tools/docs/getting-started.html) instructions for setting up your CodePush account, you can start CodePush-ifying your React Native app by running the following command from within your app's root directory:
4242

43-
```
43+
```shell
4444
npm install --save react-native-code-push
4545
```
4646

@@ -79,26 +79,38 @@ Once your Xcode project has been setup to build/link the CodePush plugin, you ne
7979

8080
1. Open up the `AppDelegate.m` file, and add an import statement for the CodePush headers:
8181

82-
```
82+
```objective-c
8383
#import "CodePush.h"
8484
```
8585

8686
2. Find the following line of code, which loads your JS Bundle from the app binary for production releases:
8787

88-
```
88+
```objective-c
8989
jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
9090
```
9191

9292
3. Replace it with this line:
9393

94-
```
94+
```objective-c
9595
jsCodeLocation = [CodePush bundleURL];
9696
```
9797

9898
This change configures your app to always load the most recent version of your app's JS bundle. On the first launch, this will correspond to the file that was compiled with the app. However, after an update has been pushed via CodePush, this will return the location of the most recently installed update.
9999
100100
*NOTE: The `bundleURL` method assumes your app's JS bundle is named `main.jsbundle`. If you have configured your app to use a different file name, simply call the `bundleURLForResource:` method (which assumes you're using the `.jsbundle` extension) or `bundleURLForResource:withExtension:` method instead, in order to overwrite that default behavior*
101101
102+
Typically, you're only going to want to use CodePush to resolve your JS bundle location within release builds, and therefore, we recommend using the `DEBUG` pre-processor macro to dynamically switch between using the packager server and CodePush, depending on whether you are debugging or not. This will make it much simpler to ensure you get the right behavior you want in production, while still being able to use the Chrome Dev Tools, live reload, etc. at debug-time.
103+
104+
```objective-c
105+
NSURL *jsCodeLocation;
106+
107+
#ifdef DEBUG
108+
jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.bundle?platform=ios&dev=true"];
109+
#else
110+
jsCodeLocation = [CodePush bundleURL];
111+
#endif
112+
```
113+
102114
To let the CodePush runtime know which deployment it should query for updates against, perform the following steps:
103115

104116
1. Open your app's `Info.plist` file and add a new entry named `CodePushDeploymentKey`, whose value is the key of the deployment you want to configure this app against (e.g. the key for the `Staging` deployment for the `FooBar` app). You can retrieve this value by running `code-push deployment ls <appName>` in the CodePush CLI, and copying the value of the `Deployment Key` column which corresponds to the deployment you want to use (see below). Note that using the deployment's name (e.g. Staging) will not work. That "friendly name" is intended only for authenticated management usage from the CLI, and not for public consumption within your app.
@@ -195,13 +207,13 @@ The simplest way to do this is to perform the following in your app's root compo
195207
196208
1. Import the JavaScript module for CodePush:
197209
198-
```
210+
```javascript
199211
import CodePush from "react-native-code-push";
200212
```
201213
202214
2. Call the `sync` method from within the `componentDidMount` lifecycle event, to initiate a background update on each app start:
203215
204-
```
216+
```javascript
205217
CodePush.sync();
206218
```
207219
@@ -219,7 +231,7 @@ Once your app has been configured and distributed to your users, and you've made
219231
220232
Example Usage:
221233
222-
```
234+
```shell
223235
react-native bundle --platform ios --entry-file index.ios.js --bundle-output codepush.js --dev false
224236
code-push release MyApp codepush.js 1.0.2
225237
```
@@ -238,7 +250,7 @@ If you are using the new React Native [assets system](https://facebook.github.io
238250

239251
2. When calling `react-native bundle`, specify that your assets and JS bundle go into the directory you created in #1, and that you want a non-dev build for your respective platform and entry file. For example, assuming you called this directory "release", you could run the following command:
240252

241-
```
253+
```shell
242254
react-native bundle \
243255
--platform ios \
244256
--entry-file index.ios.js \

0 commit comments

Comments
 (0)