I'm using this config on android:
productFlavor {
buildConfigField('String', 'MY_ANDROID_APP_KEY', 'MY_ANDROID_APP_KEY_VALUE')
}
and I'm able to get this key using:
import Config from 'react-native-config'
Config.MY_ANDROID_APP_KEY //will return MY_ANDROID_APP_KEY_VALUE
and I have this key and value on my Info.plist:
<key>MY_IOS_APP_KEY</key>
<string>$(MY_IOS_APP_KEY_VALUE)</string>
My question is: Is there some way to get MY_IOS_APP_KEY from Info.plist ?
Same question here.
Still waiting on this.
try this:
<key>MY_IOS_APP_KEY</key>
<string>__RN_CONFIG_MY_IOS_APP_KEY_VALUE</string>
@namaxinan none of the plist variables show up on my Config object, so adding a new one obviously does nothing.
Any solutions?
Have you done these steps?


thx, nhnam, you helped me a lot.
my Info.plist
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundleShortVersionString</key>
<string>$(__RN_CONFIG_VERSION_NAME)</string>
my .env
VERSION_CODE=1000000003
VERSION_NAME=0.0.4
and... it works; xcode shows "Version: $(__RN_CONFIG_VERSION_NAME)"
but JS returns correct version
import DeviceInfo from 'react-native-device-info';
console.log(DeviceInfo.getVersion()); // "0.0.4"
any workaround @nmantulenko
@nhnam yes, the extra steps didn't fix the problem
The solution I found was:
Edit Scheme/Build/Pre-actions$CONFIGURATION, calculate your env variables and echo the path to a file containing them to /tmp/envfile, like so:if [[ $CONFIGURATION == "Beta" ]]; then
echo "VERSION_CODE=${BUILD_NUMBER}" >> $ROOT_DIR/.env.beta
echo ".env.beta" > /tmp/envfile
fi
Here I'm passing the ${BUILD_NUMBER} var from the environment to react-native-config. The variables are now accessible in the Config object in the js app.
Any workaround without setting a value in the .env ?
still waiting for read from Config without setting a value in the .env..
@Darkilen @moxspoy : I don't get your idea. The .env file is used if you want to sync Configurations between JS and Native Code ( android, ios native project). Might you pls explain your problem? It is hard to know what do you want to do
Basically i want to access my secret credential from react native config but without setting from env file.
In android i use gradle property to save my credential then link into gradle file, and able to access that through Config.[VARIABLE]. In iOS, i cant do that approach. Any idea?
In a simple word, i want to share the KEY but the value is depend on how platform make it more secure
@moxspoy . In iOS, you can set directly in Build Settings, or create a XCConfig file to manage it. https://nshipster.com/xcconfig/
@nhnam In my case, I want to have access to VERSION_NAME value. For Android, it's the value I set in the build.gradle file under the key versionName but for iOS, I can't access this value at all, except if I set a new key/value pair in a .env file.
Most helpful comment
Have you done these steps?