Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

got Must call FIRApp.configure() before using FIRDatabase. error even though i already called it [closed]

I got 'Must call FIRApp.configure() before using FIRDatabase' error even though I already called it in the 'Appdelegate.swift'.This is my app delegate

like image 320
Shreyas Jamadagni Avatar asked Jul 03 '16 09:07

Shreyas Jamadagni


1 Answers

First Solution:

If you use FIRDatabase.database().reference() in your ViewController, please share the code with us. If you use something like this:

var db = FIRDatabase.database().reference()

before viewDidLoad, you can get this error. Better make this:

var db: FIRDatabaseReference!

override func viewDidLoad() {
    super.viewDidLoad()
    db = FIRDatabase.database().reference()
}

In this way, even if configure() is in finishLaunchingWithOptions, the app won't crash.

Second solution:

In AppDelegate.swift just add this lines of code:

override init() {
   FirebaseApp.configure()
   FIRDatabase.database().persistenceEnabled = true
}

When the app launch, it will go to init() method and will configure FireBase before everything else.

like image 76
Altimir Antonov Avatar answered Nov 09 '22 21:11

Altimir Antonov