Access the iOS environment from React Native.
npm install react-native-env- In XCode's "Project navigator", right click on project's name ➜
Add Files to <...> - Go to
node_modules➜react-native-env➜ addRNEnvironmentManagerIOSfolder - Add an
environment.plistto your project containing any key-values to be accessed at runtime. - Compile and have some environment
Follow the excellent, long tutorial Migrating iOS App Through Multiple Environments to derive environment.plist at build-time, based on the selected Xcode scheme.
varEnvironmentManager=require('react-native-env');// read an environment variable from React NativeEnvironmentManager.get('SOME_VARIABLE').then((val)=>{console.log('value of SOME_VARIABLE is: ',val);// => value of SOME_VARIABLE is: MY_VALUE}).catch((err)=>{console.error('womp womp: ',err.message);});// Read an environment variable synchronously.// Downside of this approach is that if environment.plist// changes during runtime, those changes will not be reflected// by getSync.varval=EnvironmentManager.getSync('SOME_VARIABLE');console.log('value of SOME_VARIABLE is: ',val);- Not sure, what do we need?
PR's welcome!