Latest Post

How to use closure button in swift How to use notificationcenter in swiftui with example Longest common subsequence program in swift

Creating a Different Product Flavors in iOS

Product Flavour in iOS :Whenever we are creating a iOS App we needed to create different build in different Environment. multiple Environment are of different Http request they may be UAT, Sit or production environment
 
Using the Product Flovor we can Target for Multiple Build variants. We can use Product Flovor for change of App name as well as Different Server URL.
 
 

Let US Start with the Product Flavor in Xcode. We can create Product Flavor for existing App as well as new App

 
Step 1: Open the Xcode Project.

Step 2: In General Click on Target Right Click on Project and Select Duplicate as shown in below image


Setup the Product Flavour in iOS Xcode

Step 3: Set the Different Target name As ProductFlavorUAT

 

Product Flavour in iOS Xcode

 
 
Step 4: select the new ProductFlavorUAT Switch to Build Setting . Search for Other Swift Flag . set as -D UAT

How to Setup the Product Flavour
. – D Example may change depending on Url Setup

Step 5: Now under Packaging search for info.plist file for that target check that target name and the info.plist name are same.

Product Flavour

Step 6:- go to the server url file and add the following code

#if  UAT

let environment : NetworkEnvironment = .UAT

// for UAT

#else

let environment : NetworkEnvironment = .Sit

// for normal

#endif

enum NetworkEnvironment {

    case Sit

    case Uat

}

let SIT = “http://leadbycodeSit.com”

let UAT = “https://leadbycodeUAt.com”

 
Step 7: Go to info.plist File an Change the name of the File

How to Setup the Product Flavour in iOS Xcode
 
Step 7: If you Have Created the Pod File you need to setup the multiple Target As Shown in below Code Add the Below Code in the Pod file as Save the Pod File
 

workspace ‘productflavor’

target ‘productflavor’ do

  use_frameworks!

    pod ‘Firebase/Analytics’

     pod ‘Firebase/Messaging’

  end

  

target ‘productflavorUAT’ do

  use_frameworks!

    pod ‘Firebase/Analytics’

    pod ‘Firebase/Messaging’

end

 
Step 8:- Select the Product Flavor and Run the Code
Product Flavour in iOS Xcode

 

 
Thus We can Add different Environment Setup Which usually Reduce the time for Setup and building of app We can Create the Archive At different Environment
 
 
Changing the App Icon Based on Flavor
 
Click on Target Select General Check the App icon and Launch image
 
Setup  iOS Xcode

In app Icon Source we can Change the Asset based on the Icon Change Also we can change the App name and the BundleId for that Flavor

 
Using this We can Change the Build Variant in Xcode


 

Leave a Reply

Your email address will not be published.