ios - Database.database().reference() 为零

标签 ios swift firebase firebase-realtime-database

我正在创建一个 iMessage 应用程序,它需要连接到与我的常规应用程序相同的数据库。

我调用 FirebaseApp.configure() 并对用户进行身份验证,但出于某种原因,在所有 Database.database().reference() 都为 null 之后,即使它应该是一个非 null 值。

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() 成为数据库的根引用而不是 nil。提前感谢您的帮助!

最佳答案

我也遇到过类似的错误。

在我的情况下,我对 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

在寻找解决方案时,我能够引用您的问题。

希望你能解决问题。

关于ios - Database.database().reference() 为零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58056429/

相关文章:

ios - 检测 UIView 在另一个 UIView 中的移动

arrays - 在 Swift 中删除数组中的重复元素

ios - Firebase 未通过 GTM 向 Google Analytics 发送相同数量的事件

c# - 如何将 DataSnapshot 与 Firebase for Unity 一起使用?

iOS UIPickerView 自定义行 View 宽度错误

ios - 向按钮添加条件(Swift)

ios - Swift func with generic where constraint is a protocol which self conforms

ios - SwiftUI 自定义 PickerStyle

ios - drawRect 绘图的动画

objective-c - 如何在swift中传递c函数指针