16

iOS Extension - Fatal Exception: com.firebase.core Default app has already been configured.

I run the Fir.configure() in the viewDidLoad() method and some events pass and get through to Firebase.

Can someone help me figure this out.. Google is not friendly enough.

PS: Yes I created a second .plist, and a second app in Firebase Console. PPS: Yes I selected the correct target for each GoogleServices plist

I'm seeking the solution..

5 Answers 5

30

I don't know if you're still looking for a solution but I had the same issue, using firebase with extension.

I ended up doing this :

if(FIRApp.defaultApp() == nil){
    FIRApp.configure()
}

This will check if the app is already configured so that there is no crash.

Sign up to request clarification or add additional context in comments.

3 Comments

The problem is my main app and my kb are two different apps in Firebase, and have 2 different plists. So this method would of not been of much use, Because both would be configured as the default app, but under different names. That solution may work, but I chose to stay with GA for the real time analytics and graphs. Firebase is not ready yet. Thanks for your late reply. PS: even if this solution worked. I would of still needed different data from the kb and the app. So if one was configured and the other was not .. that would not help my case.
This is nice. Used it in an extension context.
This pointed me to my solution. I forgot that I had already called FIRApp.configure() from AppDelegate's didFinishLaunchingWIthOptions
13

I had the same issue and I resolved it by making changes in two places in my application (check your syntax for swift version):

  1. In AppDelegate.swift override a following method:

    override init() { FirebaseApp.configure() }

  2. In your ViewController.swift's viewDidLoad() method, write this code:

    if FirebaseApp.app() == nil {
        FirebaseApp.configure()
    }
    

1 Comment

I needed this, too due to : FirebaseCore.FirebaseApp:12:21: note: 'defaultApp()' was obsoleted in Swift 3
5

Use this instead for latest firebase_ml_vision: ^0.9.3+8

if(FirebaseApp.app() == nil){
FirebaseApp.configure()
}

Comments

1

The answer is in the exception. You're configuring the app twice. You've got a few options to fix this:

1) Configure your app once in your app delegate.

2) Match a configure with an unconfigure. There is a method on FIRApp that allows you to unconfigure it (the actual name escapes me).

5 Comments

Hmm.. I ended up using google analytics, because if you do not configure Firebase, you get crash, and if you configure teice you get crash. Firebase does not seem to support extensions. Even if you can unconfigure, the problem is you unconfigure Firebase in the main app and in the extensions. This is not really supposed to happen or to be treated. Firebase is unreliable. Google analytics is the better choice. PS: I tried to configure manually using data from plist and it still wouldn't work in extensions. When you make a build for release it crashes everytime, while in debug it's 50/50
Ah, you were trying to use forename in your app and extensions? You might be able to achieve that by registering custom FIRApps for each, rather than using the default app.
So I configured 2 apps in console -> 2 plists first. I tried configuring both... Crash .. Tried only main .. Crash. Tried to put custom name for extension.. Did not load firebase. Tried entering all data into FirOptions .. Did not work in extension. I then added Google analytics and removed Firebase analytics
Ah that's unfortunate. At least you have an alternative.
+ Google analytics is in real time and much better at showing graphs than Firebase
0

I also got this issue in a today extension code too. I solved if with an extra check if your Firebase instance is already configured:

// define in your constants or somewhere
NSString* const UNIQUE_FIREBASE_INSTANCE_IDENTIFIER_WIDGET = @"Widget_FirebaseAppInstance";

if([FIRApp appNamed:UNIQUE_FIREBASE_INSTANCE_IDENTIFIER_WIDGET] == nil) // there should be only one app instance!
{
    NSString *resourceName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"FirebaseResource"];
    NSString *filePath = [[NSBundle mainBundle] pathForResource:resourceName ofType:@"plist"];
    FIROptions *options = [[FIROptions alloc] initWithContentsOfFile:filePath];
    [FIRApp configureWithName:UNIQUE_FIREBASE_INSTANCE_IDENTIFIER_WIDGET options:options];
}

In your main app you should also use a different unique name for it. So you can have multiple instances but every instance is configured only once.

1 Comment

Odd thing is, even if I use [FIRApp configure], I still get the log message saying the firebase app has not been configured.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.