本文介绍了在使用FIRDatabase之前必须调用FIRApp.configure()。即使我已经叫它错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我得到'必须在使用FIRDatabase'之前调用FIRApp.configure()'错误,即使我已经在'Appdelegate.swift'中调用了它。

如果您使用 FIRDatabase.database()。reference()

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

在viewDidLoad之前,可以得到这个错误。最好做这个:

  var db:FIRDatabaseReference! 

重写func viewDidLoad(){
super.viewDidLoad()
db = FIRDatabase.database()。reference()
}


$ b这样,即使configure()处于finishLaunchingWithOptions,应用程序也不会崩溃。



第二种解决方案

AppDelegate.swift 只需添加以下几行代码:

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

应用程序启动时,它会转到 init()方法,并将配置 FireBase 之前的所有其他。


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

解决方案

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() {
   FIRApp.configure()
   FIRDatabase.database().persistenceEnabled = true
}

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

这篇关于在使用FIRDatabase之前必须调用FIRApp.configure()。即使我已经叫它错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-08 20:34