(iOS)Manage Firebase environments for Development & Production effectively 🎯

(iOS)Manage Firebase environments for Development & Production effectively 🎯

As a mobile developer you might have used Firebase SDKs in your complex projects for different purposes.

When we create a new Firebase project in the Firebase console, we are actually creating a Google Cloud project behind the scenes. You can think of a Google Cloud project as a virtual container for data, code, configuration, and services. A Firebase project is a Google Cloud project that has additional Firebase-specific configurations and services.

Firebase provides many amazing features like data analytics, Remote config services, Crash reports, A/B testing, etc.

In this article we will learn why it is crucial to have separate configuration for Development & Production builds. 👀

Problems if we use same config environment for Development & Production (for both Android & iOS)😧

Remote config service 👀

If we are using a Remote config service in our app, it is not recommended to work on Live Remote config objects directly for development or testing purposes. It becomes very risky especially when we are manipulating the live objects as it may impact live users.

Firebase Crash report 📈

Most of the time we face App crashes while in the development or testing process. We do not want to pollute our crashlytics data report for production builds. We need to classify crashes coming from Developers/Tester & from Real users.

Analytics data 📊

For getting accurate data to understand User behaviour and react appropriately we need to segregate analytical data. Another potential source of data pollution could be from our own Development & QA process which will hamper tracking of user sessions & actions if we use same config environment.

For better project management (Access permission) 🤝

When there are multiple developers working in a team, it is not desired to give add/delete permissions of Production Firebase projects to everyone. Having a debug environment will give complete freedom & sense of relaxation especially for Freshers to work/play with.

A/B testing or any new feature ⏳

Having separate environments provides freedom to experiment or test (New features of Firebase) without risking the corruption of production data.

Firebase notification ⛳️

Having Debug environment for testing notification helps as it will be disastrous to test notification on live users

Now let’s talk about solution & how we can achieve that 🤔

Solution.jpeg

Photo by Riccardo Annandale on Unsplash

💡Solution (For iOS) :

Set up separate Firebase config environment for Development and Production

We will be creating two separate Firebase projects, which will give two separate GoogleService-Info.plist files. Now depending on the build configuration we will swap these pList files.

Steps: Refer this for Firebase set up(If not done) : firebase.google.com/docs/ios/setup

0) We need to have two separate projects with the same Bundle Id. Create another Firebase project for Debug/Development environment.

Name it appropriately so that you don’t get confuse.

1) Create an iOS App for a newly created project.

2) Now download the GoogleService-Info.plist for Debug build from console.

3) For better project structure in Xcode, create Firebase Config folder & then create Debug & Release child folders.

4) Copy the GoogleService-Info.plist corresponding to the Firebase Development environment into the Debug directory. Similarly, copy the GoogleService-Info.plist corresponding to Firebase production environment into the Release directory.

config.png

For Reference

5) Do not forget to uncheck all targets under the “Add to targets” option for both GoogleService-Info.plist files. To verify this open up the Utilities Panel (right side) and uncheck the files from any targets that may be in there for both.

We are doing this because we will configure the environment depending on the build we want.

If we want a debug build for development/testing, we will uncheck Release file & check Debug file and then create the build & vice versa.

Note : At a time only one file should be checked to targets.

Now we can either check/uncheck these files manually or we can add a script for it so that Xcode will copy desired file into final app bundle.

Thank you for reading!!! 😋

References:

This page describes how to use more than one Firebase project in your app.

Understand Firebase projects | Firebase Documentation