Xcode: Set up GoogleService for different environments (2)

Tram Ho

Previously, I used to have an article about setting up an Xcode project so that when building the app, the system will automatically know it will use the corresponding GoogleService-Info.plist file. However, my previous article is using the way to use scripts to copy files into the app while compiling code (More detail is to copy when running on run scripts). However, after a period of use and deployment, I find there are some shortcomings.

For example, when using with the guy Firebase Crashlytics, the copy of the file has been copied successfully, but Crashlytics always reports that GOOGLE_APP_ID cannot be found because the file GoogleService-Info.plist cannot be found .

Seeing that inadequacy, I have switched to a new setup. In this article I will show how I just switched. Maybe many of you have known this way before, but I still want to write this article.

Create xcode project

Here, I will create a project named ” ConfigApp “. Similar to before, I will also create Scheme to help set up which Configurations to run. However, I will not use a single Target as before, but I will create 1 more Target. In this project, I will temporarily set up for Dev and Staging environments. As shown below

After creating Target, then Xcode will create for us to add 1 Scheme corresponding to Target just finished:

Then, we will set corresponding bundle id for 2 environments.

Create Firebase App

Next, open up Firebase Console and create yourself 2 apps with bundle id corresponding to 2 Target in the project. And download 2 files GoogleService-Info.plist

After downloading 2 files, we will copy them into the Xcode project.

Set target for 2 plist files

As in the image above, after copying the file GoogleService-Info.plist , it is being checked for both Target. Now, if we build the code, we will receive an error similar to the following:

So to handle this error, very simply, we just need to uncheck the remaining Target. For the file for the Dev environment, we will uncheck Target Staging, and vice versa.

At this point, we build the code will not see any errors occur again.

Try adding Firebase Crashlytics

Next, I will try adding Firebase Crashlytics to see if there are any more errors?

After compiling, log reports that running the FirebaseCrashlytics success script.

End

This article is my end here, this is how I just used to configure personal projects. This way the setup will be easier than the previous one. However, I see it has a problem that for each Target we will need to set up separate scripts ….. If you have other ways, you can share with me. Thank you

Link github: https://github.com/dungkv-1044/ConfigApp

Share the news now

Source : Viblo