react-native-config-info
v1.0.0
Published
Read configuration values from Info.plist (iOS) or from resources strings.xml (Android)
Downloads
3
Maintainers
Readme
Installation
npm install react-native-config-info
cd ios && pod install
Prerequisite
Add your values into your Info.plist (iOS) or strings.xml (Android).
iOS
ios/[project]/Info.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BackendUrl</key>
<string>https://api.example.com</string>
</dict>
</plist>
Android
android/app/src/main/res/values/strings.xml
<resources>
<string name="BackendUrl">https://api.example.com</string>
</resources>
Usage
Asynchronous getters
Get your values.
import ConfigInfo from 'react-native-config-info';
async function main() {
await ConfigInfo.get('BackendUrl'); // https://api.example.com
await ConfigInfo.getOrThrow('BackendUrl'); // https://api.example.com
await ConfigInfo.get('UnknownKey'); // null
await ConfigInfo.getOrThrow('UnknownKey'); // [RNConfigInfoException: 'UnknownKey' value is missing from ….]
}
Synchronous getters
Get your values synchronously.
As said in the official documentation, synchronous methods are not recommended.
Only use them if you have no other option.
import ConfigInfo from 'react-native-config-info';
ConfigInfo.getSync('BackendUrl'); // https://api.example.com
ConfigInfo.getSyncOrThrow('BackendUrl'); // https://api.example.com
ConfigInfo.getSync('UnknownKey'); // null
ConfigInfo.getSyncOrThrow('UnknownKey'); // [RNConfigInfoException: 'UnknownKey' value is missing from ….]
License
MIT © Rémy Abitbol.