我正在创建一个iMessage应用程序,它需要连接到与我的常规应用程序相同的数据库。
我调用FirebaseApp.configure()并对用户进行身份验证,但是由于某种原因,Database.database().reference()是空的,尽管它应该是一个非空值。
var ref: DatabaseReference!
override func viewDidLoad() {
super.viewDidLoad()
if FirebaseApp.app() == nil {
FirebaseApp.configure()
Database.database().isPersistenceEnabled = true
print("FIREAPP Configed")
print(FirebaseApp.app())
signIn() //Use kept google credentials to log in
configureDatabase()
}
}
func configureDatabase() {
ref = Database.database().reference()
print(ref)
}我期望Database.database().reference()作为数据库的根引用,而不是零。谢谢您提前提供帮助!
发布于 2019-10-08 12:42:21
我也在与类似的错误作斗争。
在我的情况下,我对CocoaPods的理解是不够的。
在此之前:
target 'MyApp' do
use_frameworks!
pod 'Firebase/Database'
target 'MyAppTests' do
inherit! :search_paths
end
target 'MyFrameWorkA' do
inherit! :search_paths
end
target 'MyFrameWorkB' do
inherit! :search_paths
end
end之后:
abstract_target 'AnyTargets' do # Anything that doesn't duplicate the actual target name
use_frameworks!
pod 'Firebase/Database'
target 'MyApp' do
end
target 'MyAppTests' do
end
target 'MyFrameWorkA' do
end
target 'MyFrameWorkB' do
end
end在寻找解决方案时,我能够咨询你的问题。
我希望你能解决这个问题。
发布于 2019-09-23 06:12:29
你似乎对这句话很困惑:
ref = Database.database().reference()这只是建立了对数据库根的引用。它还没有加载任何数据。
若要实际加载数据,请将侦听器附加到引用:
ref.observeSingleEvent(of: .value, with: { (snapshot) in
print(snapshot.value)
}) { (error) in
print(error.localizedDescription)
}请注意,数据是异步从Firebase加载的。任何需要数据的代码,都必须是在中--完成处理程序(如上)--或者从那里调用。
还请参阅读写数据上的Firebase文档。
发布于 2020-12-10 20:29:03
我也被这个错误绊倒了,我的解决方案是在我的荚文件中添加“Firebase/Core”。我不确定这是否是常识,但在建立我的防火墙数据库项目,我从来没有读过关于添加这个特定的荚。我的pod文件在重写之后:
target 'MyApp' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
# Pods for MyApp
# add pods for desired Firebase products
# https://firebase.google.com/docs/ios/setup#available-pods
pod 'Firebase/Database'
pod 'Firebase/Core'
endhttps://stackoverflow.com/questions/58056429
复制相似问题