Skip to content

Commit 4b2e3f4

Browse files
committed
Use environment.plist instead of process env.
Variables defined in the Scheme’s “Run” section are only available when running a build attached to Xcode. Instead, this revision reads from an environment.plist file that is available at all times.
1 parent 9000df2 commit 4b2e3f4

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ Access the iOS environment from React Native.
77
1. `npm install react-native-env`
88
2. In XCode's "Project navigator", right click on project's name ➜ `Add Files to <...>`
99
3. Go to `node_modules``react-native-env` ➜ add `RNEnvironmentManagerIOS` folder
10-
4. Add environment variable(s) to your XCode scheme(s) (see screenshot below)
11-
4. Compile and have some environment
10+
4. Add an `environment.plist` to your project containing any key-values to be accessed at runtime.
11+
5. Compile and have some environment
1212

13-
![screenshot_6_1_15__10_17_pm](https://cloud.githubusercontent.com/assets/54157/7927305/32e65e24-08ac-11e5-9837-9801611fda2f.png)
13+
### Per-environment Config
1414

15+
Follow the excellent, long tutorial [Migrating iOS App Through Multiple Environments](http://www.blackdogfoundry.com/blog/migrating-ios-app-through-multiple-environments/) to derive `environment.plist` at build-time, based on the selected Xcode scheme.
1516

1617
### Usage
1718

RNEnvironmentManagerIOS/RNEnvironmentManagerIOS.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ @implementation RNEnvironmentManagerIOS
77

88
RCT_EXPORT_METHOD(get:(NSString *)name callback:(RCTResponseSenderBlock)callback) {
99
@try {
10-
NSDictionary *env = [[NSProcessInfo processInfo] environment];
10+
NSDictionary *env = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"environment" ofType:@"plist"]];
1111
if ([env objectForKey:name]) {
1212
callback(@[[NSNull null], env[name]]);
1313
} else {

0 commit comments

Comments
 (0)