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

瘦欲@ 提交于 2019-12-03 12:38:48

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.

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()
    }
    

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).

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!