Xcode: Set up GoogleService for different environments.

Tram Ho

Hi everyone, in this article I will share how I have learned and applied it in projects that need to integrate Google service into different environments such as Development, Staging, Production. Hope this article will help you save time when needed. Currently, each environment I see will need a different bundle id, corresponding to google services, we will also need different GoogleService-Info.plist files. Below I will guide you to integrate it into the desired environment.

Create folder

First, we need to open the folder containing the project. Here we will need to create a directory to contain the GoogleService-Info.plist file. I create folders and subdivision as shown below: With the subdirectories Dev, Staging, Production, we will copy the corresponding GoogleService-Info.plist file for the environment.

Add the folder to the project

After preparing the corresponding GoogleService-Info.plist folders and files. Open your project, next, right click on the folder containing the newly created folder -> Add files to “…..” Note select: Create folder reference After adding the file to the project, it will look like this: After successfully adding the directory containing the file, we will need a script to be able to use the corresponding GoogleService-Info.plist file.

Config script

Next, we will need to find the Build phases tab. Here we need to create New Run Script Phase . Here I will name it Config Google Service I will use the script below to copy the GoogleService-Info.plist file into the project corresponding to the environment we configure.

In the above code, I have noted the steps in the script that will be executed, you just need to spend some time reading to understand how the code works, in addition, you can change it to fit. your project. Hopefully this article will be able to help you not only in configing google service but also in other cases.

Share the news now

Source : Viblo