Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The default app has not been configured yet

I'm trying to upgrade my app to the new version of Firebase. I went through the setup guide and edited all of my code to match the new syntax. However, when I run the app, I get these two errors.

The default app has not been configured yet.
Terminating app due to uncaught exception 'MissingDatabaseURL', reason: 'Failed to get FIRDatabase instance: FIRApp object has no databaseURL in its FirebaseOptions object.'

I have FIRApp.configure() in the AppDelegate and I have the GoogleServices-Info.plist imported into my project. The plist has all of the correct info as well. Anyone else running into this or know how to fix it?

like image 670
Michael Williams Avatar asked May 19 '16 21:05

Michael Williams


4 Answers

Here's the answer to your problem:

To configure Firebase you have to execute FIRApp.configure() somewhere. After this is done you can use let firebaseDatabaseReference = FIRDatabase.database().reference() to get a reference to that database and start using it. The problem isn't with Firebase "per se" but with how Swift behaves.

If you put FIRApp.configure() in your AppDelegate func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool and then in the MyDatabase class you use let firebaseDatabaseReference = FIRDatabase.database().reference() outside of your declared functions sometimes the code FIRDatabase.database().reference() executes before the application didFinishLaunchingWithOptions function is executed.

Essentially your class is trying to get a reference to the Firebase database before it has a chance to configure itself, generating the error in the console "The default app has not been configured yet."

Note: This doesn't happen all the time, sometimes the application is slow to start, in iOS Simulator for example, and it doesn't have a chance to finish before MyDatabase "let" executes and tries to get a reference.

That is why moving the FIRApp.configure() code to override init() in AppDelegate works, essentially it makes sure the configure code gets executed when AppDelegate is initialised (in this and most cases, before MyDatabase is initialised)

override init() {
   super.init()
   FIRApp.configure()
   // not really needed unless you really need it FIRDatabase.database().persistenceEnabled = true
}

Also make sure you super.init() (so you super classes get the "message") so you override doesn't do more harm than good.

like image 117
unom Avatar answered Nov 13 '22 03:11

unom


I'm also using Fabric and in my case it was the order of Fabric and Firebase initializations. I had to initialize Firebase first.

So changing

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    Fabric.with([Crashlytics.self])
    FirebaseApp.configure()
    ...
}

to:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    FirebaseApp.configure()
    Fabric.with([Crashlytics.self])
    ...
}

fixed the problem.

like image 26
algrid Avatar answered Nov 13 '22 04:11

algrid


In AppDelegate.m, outside of didFinishLaunchingWithOptions,

override init() {
   FIRApp.configure()
   FIRDatabase.database().persistenceEnabled = true
}
like image 4
Michael Williams Avatar answered Nov 13 '22 03:11

Michael Williams


Make sure you are having DATABASE_URL key in your GoogleService-Info.plist

like image 2
Mohammad Zaid Pathan Avatar answered Nov 13 '22 03:11

Mohammad Zaid Pathan