Part 2 - iOS configuration for environment variables
It is Part 2 in a series of the setup guide to configure the Staging and Production environments in the application.
To configure the iOS, we will have one scheme per environment file, so that we can easily toggle between them.
Start by creating a new scheme:
- In the Xcode menu, go to Product > Scheme > Edit Scheme
- Click Duplicate Scheme in the bottom
- Give it appropriate name on the top left. For instance: “ConfigDemo (staging)”
Then edit the newly created scheme to make it use a different env file. From the same “Manage Scheme” window:
- Expand the “Build” settings on left
- Click “Pre-actions”, and under the plus sign, select “New Run Script Action”
- Where it says Type a script or drag a script file, type:
echo ".env.staging" > /tmp/envfile
- Also, make sure that the scheme is shared so that it can be pushed to the VCS and other team members can also get this scheme when they pull the code from the VCS:
- Press Close
Now, repeat exactly the same process for the production configuration and name this scheme with the name ConfigDemo (production) and enter the below script for the Pre-actions script for production:
echo ".env.production" > /tmp/envfile
Now, we have everything set up for iOS for the environment variables.
To run the staging build variant for iOS, run the following command in the terminal inside the root directory of your application:
react-native run-ios --scheme 'ConfigDemo (staging)'
Similarly, to run the Production variant, we can do this by hitting the command:
react-native run-ios --scheme 'ConfigDemo (production)'
Further, you can also create 2 scripts in the package.json file to run the desired variant like:
To run the iOS build, select the desired Scheme and hit Run. The right env variables will be loaded into the Config object.
That is it for the iOS Configuration.
To configure Bundle Ids, App Name and Google Service Files, please follow the Part 3.