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

  1. First, create 3 separate env files for each environment:

    • .env.dev

    • .env.staging

    • .env.prod

triangle-exclamation

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)

Duplicate the default scheme twice, then rename the original
circle-info

Make sure to tick the "Shared" box for each scheme

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

  • Development.xcconfig

  • Staging.xcconfig

  • Production.xcconfig

Select .xcconfig
circle-info

Make sure to select the project target when creating the files

Add to the project target

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

Create a Debug and Release config for each scheme
circle-info

Make sure to select the correct configuration file for the main target (the files created in step #3)

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

Select the correct config for the scheme for Run, Test, Profile, Analyze and Archive

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

Add to the Build -> Pre-actions step
circle-info

You'll need to do this for each of the 3 schemes

7. Add the following to your Podfile, just under the platform specifier

circle-info

Ensure to replace Project with the name of the target

8. Reinstall Cocoapods:

  • Delete the .xcworkspace file

  • Delete the Podfile.lock file and Pods/ directory

  • Keep 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:

Example

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

Make sure to remember the names for the next step

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

Add the corresponding App Icon Set for each configuration

13. Update the start scripts in package.json

Pick a scheme for each environment

Last updated

Was this helpful?