Working with multiple build environments in iOS

23 / Jun / 2015 by vishal.gupta 2 comments

While working in any iOS application, we need to build our app for multiple environments i.e. Development, Production, UAT, QA. Now a days it becomes a common practice for any app to integrate social media, analytics, crash reporter, third party tools, sdks inside apps. Each of these environment have different set of urls to point to these servers, keys for these social media, analytics, crash reporter, third party tools, sdks.

If we are integrating many third party tools, social media platforms, sdks in our app then it becomes more complex for a iOS developer, while running the app for different environment, ensure that app is using the correct keys for these third party tools, social media platforms, sdks for the particular environment.

For the simplex and correct use of these servers with correct set of keys we have to work with multiple Xcode schemes and custom project configurations for build environments inside the app. We need to be able to quickly and easily switch between configurations without messing with compiler flags or manually modifying variables in your project.

Create A New Project:

when we create a new project, select your project in the project navigator and see info tab, it automatically comes with 1 scheme (named with project name) and 2 configurations (named ‘Debug’ & ‘Release’) without any configuration file.



Creating Configurations:

We will go ahead by creating Development, Production, UAT, QA environments. So we will create 4 configurations each for an environment.

Click the + button below the configuration tab, select ‘duplicate debug’ for each new configuration and provide the name for it.



Adding Xcode Schemes:

Add Xcode scheme for each of these environments by following the steps below.

  1.  Click the current scheme, select New Scheme from the menu that appears
  2.  Name the new scheme Development.
  3.  With the new scheme selected, click the scheme and select Edit Scheme from the menu.
  4.  Select Run Configurable from the left pane, open the Info tab at the top, and set the Build Configuration to Development.
  5.  Create an Xcode scheme for the UAT , QA and Production configurations by repeating the above steps.





Adding Configuration Settings File:

Add Configuration Settings File in your project.

  1.  Select project in your project navigator pane.
  2.  Click + button below in project navigator pane. Select file option.
  3.  Select other under iOS section. Select configuration Settings file. Click next. Name it and add.
  4.  repeat 1-3 for each configuration.




Select Configuration Files for the Configurations:

Select Project in Project navigator pane. Go to configurations section. Expand Development, select development configuration file for it in all three section.

Repeat the above process for UAT , QA and Production.



Adding Environment variables in configuration file:

Add your entries in Configuration files i.e. I will add some key for Base_url and protocol to call a web service.





Add environment variables into Info.plist:

Add the entries in info.plist file as well.



Code to fetch environment variables:

Now to fetch base url and protocol from info.plist use following code.

baseUrl = [[NSBundle mainBundle] infoDictionary][@"BaseUrl"];

protocol = [[NSBundle mainBundle] infoDictionary][@"Protocol"];

Now select the particular scheme to run the app in particular environment.


comments (2)

  1. Jade

    Hi. Thank you for this wonderful tutorial. I have a question though. Where should the code of “baseUrl = [[NSBundle mainBundle] infoDictionary][@”BaseUrl”];” be added?

    Thank you.


Leave a Reply to Jade Cancel reply

Your email address will not be published. Required fields are marked *