React-native-config: Is there any way to get a key value from Info.plist on iOS ?

Created on 12 Dec 2018  路  16Comments  路  Source: luggit/react-native-config

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 ?

Most helpful comment

Have you done these steps?

Screenshot 2019-03-29 at 9 29 45 PM
Screenshot 2019-03-29 at 9 29 56 PM

All 16 comments

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?

Screenshot 2019-03-29 at 9 29 45 PM
Screenshot 2019-03-29 at 9 29 56 PM

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:

  1. Tap the app name next to the run button on Xcode
  2. Tap Edit Scheme/Build/Pre-actions
  3. Based on $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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rpereira picture rpereira  路  3Comments

kidnapkin picture kidnapkin  路  3Comments

jemise111 picture jemise111  路  4Comments

Husnain-Asharf picture Husnain-Asharf  路  3Comments

himanshu-satija picture himanshu-satija  路  3Comments