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
➜ addRNEnvironmentManagerIOS
folder - Add an
environment.plist
to 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.
var EnvironmentManager = require('react-native-env');
// read an environment variable from React Native
EnvironmentManager.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);
});
- Not sure, what do we need?
PR's welcome!