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

梦想与她 提交于 2020-01-01 04:43:36

问题


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


回答1:


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.




回答2:


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



回答3:


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




回答4:


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.



来源:https://stackoverflow.com/questions/38536257/ios-extension-fatal-exception-com-firebase-core-default-app-has-already-been

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