默认应用程序尚未配置 [英] The default app has not been configured yet

查看:135
本文介绍了默认应用程序尚未配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将我的应用升级到新版本的Firebase。我浏览了设置指南,并编辑了所有的代码以匹配新的语法。但是,当我运行应用程序,我得到这两个错误。

 默认应用尚未配置。 
由于未捕获的异常MissingDatabaseURL而终止应用程序,原因:'无法获取FIRDatabase实例:FIRApp对象的FirebaseOptions对象中没有databaseURL'

我在AppDelegate中有 FIRApp.configure(),并将GoogleServices-Info.plist导入到我的项目中。 plist也有所有正确的信息。任何人遇到这个问题或知道如何解决它?

解决方案

这是您的问题的答案:

要配置Firebase,您必须在某处执行 FIRApp.configure()。完成之后,您可以使用 let firebaseDatabaseReference = FIRDatabase.database()。reference()来获取对该数据库的引用并开始使用它。如果你把 FIRApp.configure() 在您的AppDelegate func应用程序(application:UIApplication,didFinishLaunchingWithOptions launchOptions:[NSObject:AnyObject]?) - > Bool 然后在 MyDatabase类中使用 let firebaseDatabaseReference = FIRDatabase.database()。reference()代码 FIRDatabase.database()。reference()在执行之前执行 outside 执行应用程序didFinishLaunchingWithOptions 函数。

本质上,您的类正尝试在Firebase数据库之前引用,它有机会自行配置,在控制台中生成错误默认应用尚未配置。



注意:这不会一直发生,有时应用程序启动缓慢模拟器,例如,它没有机会在MyDatabaselet执行之前完成并试图获得一个引用。



这就是为什么移动FIRApp.configure()代码覆盖AppDelegate中的init()工作,本质上它确保配置代码在AppDelegate初始化时执行(在这种情况下以及大多数情况下,在MyDatabase被初始化之前)

$ pre $ 覆盖init(){
super.init()
FIRApp.configure()
//真的不需要,除非你真的需要它FIRDatabase.database()。persistenceEnabled = true
}

。在它()(所以你超类获得消息),所以你重写并没有做更多的伤害比好。


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?

解决方案

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.

这篇关于默认应用程序尚未配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆