{"id":21565,"date":"2015-06-23T18:35:17","date_gmt":"2015-06-23T13:05:17","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=21565"},"modified":"2022-01-11T11:53:07","modified_gmt":"2022-01-11T06:23:07","slug":"working-with-multiple-build-environments-in-ios","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/working-with-multiple-build-environments-in-ios\/","title":{"rendered":"Working with multiple build environments in iOS"},"content":{"rendered":"<p style=\"text-align: left;\">While <a title=\"iOS Application Development Services\" href=\"http:\/\/www.tothenew.com\/mobile-ios-application-development-services\">working in any iOS application<\/a>, we need to build our app for multiple environments i.e. <i>Development, Production, UAT, QA<\/i>. Now a days it becomes a common practice for any app to integrate <i>social media, analytics, crash reporter, third party tools, sdks<\/i> inside apps. Each of these environment have different set of urls to point to these servers, keys for these <i>social media, analytics, crash reporter, third party tools, sdks<\/i>.<\/p>\n<p>If we are integrating many <i>third party tools, social media platforms, sdks<\/i> in our app then it becomes <a title=\"iOS App Creator\" href=\"http:\/\/www.tothenew.com\/mobile-ios-application-development-services\">more complex for a iOS developer<\/a>, while running the app for different environment, ensure that app is using the correct keys for these <i>third party tools, social media platforms, sdks<\/i> for the particular environment.<\/p>\n<p>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.<\/p>\n<p><strong>Create A New Project:<\/strong><\/p>\n<p>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 \u2018Debug\u2019 &amp; \u2018Release\u2019) without any configuration file.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-21568\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/06\/14.png\" alt=\"1\" width=\"1243\" height=\"771\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Creating Configurations:<\/strong><\/p>\n<p>We will go ahead by creating <i>Development, Production, UAT, QA<\/i> environments. So we will create 4 configurations each for an environment.<\/p>\n<p>Click the + button below the configuration tab, select \u2018duplicate debug\u2019 for each new configuration and provide the name for it.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-21570\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/06\/32.png\" alt=\"3\" width=\"1244\" height=\"777\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Adding Xcode Schemes:<\/strong><\/p>\n<p>Add Xcode scheme for each of these environments by following the steps below.<\/p>\n<ol>\n<li>\u00a0Click the current scheme, select New Scheme from the menu that appears<\/li>\n<li>\u00a0Name the new scheme Development.<\/li>\n<li>\u00a0With the new scheme selected, click the scheme and select Edit Scheme from the menu.<\/li>\n<li>\u00a0Select Run Configurable from the left pane, open the Info tab at the top, and set the Build Configuration to Development.<\/li>\n<li>\u00a0Create an Xcode scheme for the <em>UAT , QA<\/em> and <em>Production<\/em> configurations by repeating the above steps.<\/li>\n<\/ol>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-21571\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/06\/42.png\" alt=\"4\" width=\"1245\" height=\"800\" \/><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-21572\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/06\/51.png\" alt=\"5\" width=\"1242\" height=\"800\" \/><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-21573\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/06\/61.png\" alt=\"6\" width=\"1243\" height=\"800\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Adding Configuration Settings File:<\/strong><\/p>\n<p>Add Configuration Settings File in your project.<\/p>\n<ol>\n<li>\u00a0Select project in your project navigator pane.<\/li>\n<li>\u00a0Click + button below in project navigator pane. Select file option.<\/li>\n<li>\u00a0Select other under iOS section. Select configuration Settings file. Click next. Name it and add.<\/li>\n<li>\u00a0repeat 1-3 for each configuration.<\/li>\n<\/ol>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-21574\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/06\/71.png\" alt=\"7\" width=\"1242\" height=\"800\" \/><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-21575\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/06\/82.png\" alt=\"8\" width=\"1245\" height=\"800\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Select Configuration Files for the Configurations:<\/strong><\/p>\n<p>Select Project in Project navigator pane. Go to configurations section. Expand Development, select <em>development<\/em> configuration file for it in all three section.<\/p>\n<p>Repeat the above process for <em>UAT , QA<\/em> and <em>Production<\/em>.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-21576\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/06\/92.png\" alt=\"9\" width=\"1244\" height=\"800\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Adding Environment variables in configuration file:<\/strong><\/p>\n<p>Add your entries in Configuration files i.e. I will add some key for Base_url and protocol to call a web service.<\/p>\n<pre><em>BASE_URL = fameplus-api.qa3.intelligrape.net<\/em>\r\n\r\n<em>PROTOCOL = http<\/em>\r\n<\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-21577\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/06\/103.png\" alt=\"10\" width=\"1241\" height=\"800\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Add environment variables into Info.plist:<\/strong><\/p>\n<p>Add the entries in<em> info.plist<\/em> file as well.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-21578\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/06\/112.png\" alt=\"11\" width=\"1246\" height=\"800\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Code to fetch environment variables:<\/strong><\/p>\n<p>Now to fetch base url and protocol from info.plist use following code.<\/p>\n<pre><em>baseUrl = [[NSBundle mainBundle] infoDictionary][@\"BaseUrl\"];<\/em>\r\n\r\n<em>protocol = [[NSBundle mainBundle] infoDictionary][@\"Protocol\"];<\/em>\r\n<\/pre>\n<p>Now select the particular scheme to run the app in particular environment.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":117,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":16},"categories":[1400,1],"tags":[1906,4848,1907,1909,1908],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/21565"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/117"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=21565"}],"version-history":[{"count":1,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/21565\/revisions"}],"predecessor-version":[{"id":54513,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/21565\/revisions\/54513"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=21565"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=21565"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=21565"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}