How to configure Firebase Google-Services.json for different targets in iOS?

By | November 3, 2018

Once you have different Google-Services.json for different targets for your firebase applications, you may be wondering how all can have same filenames and configure for different targets. However the solution is simple.

Initial Steps

* Create new directory for each directory inside for project folder. Make sure the folder name is different from the target name
(you can just put an underscore in front of the target name folder).

* Once you have created all the folders for each target, copy the corresponding Google-Services.json into it. Then Drag each folder to the xcode project directory and check the checkbox for each app.

* Make sure you select each folder and check if it is properly selected for each target. You can click on a folder and on the ‘Target Membership’ tab on the right side, you can see for what target each folder is selected.

Update info.plist

Go to the target info.plist and add one more key to it.
Let’s say it “AppDirectory”, give the value of each folder name for each target.

Lets say your target is “MyApp1” and the folder you created for MyApp1 is “_MyApp1”, the ‘AppDirectory’ value will be “_MyApp1”.


This is how you usually configure the Firebase App.

In Objective C

 [FIRApp configure]

With Different targets, we do like this.

Now open the AppDelegate.m and copy the below function.

 +(void) initFirebase{
  NSString *appDir = [[NSBundle mainBundle] objectForInfoDictionaryKey:APP_DIRECTORY];
  NSString *filePath = [[NSBundle mainBundle] pathForResource:FB_CONFIG_FILE ofType:PLIST inDirectory:appDir];
  FIROptions *options = [[FIROptions alloc] initWithContentsOfFile:filePath];
  [FIRApp configureWithOptions:options];

And Call above function in didFinishLaunchingWithOptions

-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
    [AppDelegate initFirebase];

All set. Go ahead and test your app.

Leave a Reply

Your email address will not be published. Required fields are marked *