【发布时间】:2017-12-25 03:12:15
【问题描述】:
我完成了在我的应用上设置 Firebase 的步骤,并且测试良好。但是,当我创建了一个自定义 swift 类来创建管理数据库的函数时,它崩溃并显示“无法获取默认的 firdatabase 实例。必须在使用 firdatabase 之前调用 firapp.configure()”。我在 AppDelegate 中调用了 configure(),但它似乎没有传递给我的自定义类。下面是我得到的错误,我调用 FirebaseApp.configure() 的 AppDelegate 部分,以及自定义类。提前致谢。
DatabaseTestApp[7814:336288] *** 由于未捕获的异常“FIRAppNotConfigured”而终止应用程序,原因:“无法获取默认 FIRDatabase 实例。必须在使用 FIRDatabase 之前调用 FIRApp.configure()。'
import UIKit
import Firebase
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
FirebaseApp.configure()
return true
}
}
我的自定义类:
import Foundation
import UIKit
import FirebaseDatabase
class FirebaseClass
{
var ref:DatabaseReference?
init ()
{
ref = Database.database().reference()
}
}
【问题讨论】:
-
请发布 logcat 和您的代码,以便人们可以帮助您。一个人无法通过正确的信息帮助别人
-
嗨 UmarZaii,我编辑了我的帖子以显示所有这些信息。
标签: swift class firebase appdelegate