问题描述
我得到'必须在使用FIRDatabase'之前调用FIRApp.configure()'错误,即使我已经在'Appdelegate.swift'中调用了它。
如果您使用 FIRDatabase.database()。reference()
在您的ViewController中,请与我们分享代码。如果你使用这样的东西: 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()。即使我已经叫它错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!