Change To URL Production By Custom Configuration with cocoapods in iOS App

yusef naser
4 min readFeb 10, 2020

--

Introduction

When you work on iOS app may be you have two Base URL or more (development and production) urls, and you may some times forgot to change url before deploy app on appstore, in this tutorial we will create custom configuration to handle this issue with cocoapods and url automatically changed when deploy app

Cocoapods Configurations

When you create project and setup cocoapods, cocoapod created its custom configuration like this image

So we need to create our configuration for every stage (Debug, Release).

Create Custom Configuration

In the top file in project right click and click on new file

choice “Configuration Settings File” Then you see this dialog and write the name of file “DebugConfig” , and create another configuration file with name “ReleaseConfig”

Now you can see the two file that you created

Include cocoapod configuration

We need to add url for every stage in configuration file and include cocoapod configs

in config file add word “#include” and drag cocoapod config file into your file , you can see the path of file

delete first part in this path until “Pods/Target Support Files……” and add this path in double quotes like this image

we add the back slash “\” to prevent make line as a comment

in ReleaseConfig file repeat previous steps for release

After that change the add config file to your project

then rebuild the project and it will be success

Add variable in info.plist

after build success we need to access Backend_URL value from our config, we do that by info.plist. in info file add variable BackendURL

Access variable in info.plist

the last step is access info.list variable by this code

when you run you should see the debug url

if you want to run release build config , you can select from topBar

Product → Schema → EditSchema and select Build Configuration is “Release”

After you run , you should see the release url

Attention please :

What if you have more than two stage like testing, so we need to create Test configuration,

in configurations list you can click on + and select any duplicate

rename the new configuration with “Test

now we need to run command “pod install” to make cocoapod creating its configuration and you can see cocoapod configuration for test

and you can create your configuration file like previous steps and the final result look like this

and change the test config

Now you can run Test build config

and the result is

Finally when you archive your app to deploy on app store it will be automatically change to url production

Github : https://github.com/Yusef-Naser/Custom_configuration

Follow Me:
Twitter
Linkedin

--

--