Environments
Setting up production, staging and dev environments
We use 3 different environments for our CA build flow:
Environment
Description
API
Dev
Day to day environment for use by developers locally
localhost/testapi
Staging
Internal testing & UAT (Beta)
testapi
Production
Customer facing, app store/external flight
api
These 3 different environments result in 3 different Xcode schemes (Dev, Staging, Production). Instructions for setting up these schemes are below.
Setup
First, create 3 separate env files for each environment:
.env.dev.env.staging.env.prod

Don't add any sensitive information to these files, they will be committed to the repo
2. Open the default scheme and press Duplicate Scheme. Duplicate again, and rename the existing scheme, until you get 3 schemes in the format. Make sure to set it as Shared.
Project (Development)
Project (Staging)
Project (Production)

3. Create a new folder called Config, and add 3 configuration files to it called:
Development.xcconfigStaging.xcconfigProduction.xcconfig


4. Add the following to each file, changing the values accordingly
5. Go to Project Name -> Select the Project -> Info and duplicate the existing configurations so that there are 2 configurations for each scheme - 6 in total

5. Update each scheme's build configuration to point to the correct config

6. Add a pre-actions script to the build phase to copy the correct .env file for each scheme. Be sure to select the correct target for the "Provide build settings from" dropdown

7. Add the following to your Podfile, just under the platform specifier
8. Reinstall Cocoapods:
Delete the
.xcworkspacefileDelete the
Podfile.lockfile andPods/directoryKeep the Podfile
Rerun
pod install
You’ll see in Terminal that CocoaPods did not set the configuration since we already set custom configurations. CocoaPods provides a link to be included in each

Add each path to the top of the corresponding .xcconfig file by importing it:

9. Open Info.plist and set:
Key
Value
Bundle identifier
$(APP_BUNDLE_ID)
Bundle display name
$(APP_NAME)
10. Open Project Settings -> Target -> Build Settings and find the Packaging section. Set Product Bundle Identifier $(APP_BUNDLE_ID) to pull in the correct bundle ID for each build.
11. Add an app icon for each scheme

12. Go to the Project Settings -> Build Settings and find Asset Catalog Compiler - Options. Under Asset Catalog App Icon Set Name, add the name of the icon set you added in step #10

13. Update the start scripts in package.json

Last updated
Was this helpful?