Skip to content

Commit

Permalink
update readme to show how to pick env files in ios
Browse files Browse the repository at this point in the history
  • Loading branch information
pedro committed Mar 4, 2016
1 parent 57ea6c3 commit e40737d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
8 changes: 7 additions & 1 deletion Example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Just a single app accessing config variables from `.env` and `.env.prod`.


## Running on Android
## Running in Android

By default it will read variables from `.env`:

Expand All @@ -16,3 +16,9 @@ To read from another file just specify it with `ENVFILE`, like:
```bash
$ ENVFILE=.env.prod react-native run-android
```

## Running in iOS

Open the Xcode project file in `Example/ios/Example.xcodeproj`.

Notice there are two schemes setup for the application: "Example" runs the default build, reading vars from `.env` – and "Example (prod)" is configured to read from `.env.prod`.
31 changes: 29 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,40 @@ Xcode support is missing; variables declared in `.env`. can be consumed from Re

Save config for different environments in different files: `.env.staging`, `.env.production`, etc.

By default react-native-config will read from `.env`, but you can change it setting `ENVFILE` before running it, like:
By default react-native-config will read from `.env`, but you can change it when building or releasing your app.


#### Android

To pick which file to use in Android, just set `ENVFILE` before building/running your app. For instance:

```
$ ENVFILE=.env.staging react-native run-android
```

This is only support in Android at the moment – The iOS equivalent should be coming soon.
#### iOS

Support for Xcode is still a bit experimental – but at this moment the recommendation is to create a new scheme for your app, and configure it to use a different env file.

To create a new scheme, open your app in Xcode and then:

- Click the current app scheme (button with your app name next to the stop button)
- Click "Manage Schemes..."
- Select your current scheme (the one on top)
- Click the settings gear below the list and select "Duplicate"
- Give it a proper name on the top left. For instance: "Myapp (staging)"

To make a scheme use a different env file, on the manage scheme window:

- Expand the "Build" settings on left
- Click "Pre-actions", and under the plus sign select "New Run Script Action"
- Fill in with this script on the dark box, replacing `.env.staging` for the file you want:

```
echo ".env.staging" > /tmp/envfile
```

This is still experimental and obviously a bit dirty – let me know if you have better ideas on this front!


## Setup
Expand Down

0 comments on commit e40737d

Please sign in to comment.