ios - 当我尝试引用 firebase 数据库时应用程序崩溃

标签 ios swift firebase

我是 Swift 和 Firebase 的新手。我当前的项目是在 Xcode 8 中。我遵循了一些教程,但现在我被卡住了。我可能已经发现了问题。当我尝试引用数据库时,应用程序崩溃了。这发生在以下行:

var ref = Firebase.Database().reference()

我尝试了很多方法,例如添加以下代码行:

var ref: DatabaseReference!
ref = Database.database().reference()

但这没有用。我还尝试删除一些文件并制作一个新的 podfile,并在终端上执行与之前相同的操作。在我的 Podfile 中,我有以下内容:

pod 'Firebase/Database'
pod 'Firebase/Auth'
pod 'Firebase/Storage'
pod 'Firebase/Core'

这是我当前的代码:

import UIKit
import Firebase

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
    var window: UIWindow?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        FirebaseApp.configure()
        var ref = Firebase.Database().reference()

        window = UIWindow(frame: UIScreen.main.bounds)
        window?.makeKeyAndVisible()
        window?.rootViewController = UINavigationController(rootViewController: ViewController())

        return true
    }

也许这是一个愚蠢的问题,但我被卡住了。

最佳答案

我只使用下面的代码,因为您不需要调用 Firebase.Database:

let reference = Database.database().reference()

在您的 AppDelegate 文件中,您不希望做任何您想做的事情。您需要在 Controller 类中执行此操作。例如,XCode 为您创建的默认 ViewController 类。有任何问题,请告诉我。我们都去过那里!

关于ios - 当我尝试引用 firebase 数据库时应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48372392/

相关文章:

ios - 在 UITableViewCell 内渲染 UIWebView

ios - 使用 Firebase 在 iOS 13.2 中登录导航/Segue

ios - UITextView在IOS中消耗大量内存

ios - Swift AnyObject 作为 String 动态转换失败

iphone - UITableView 代表

java - 如何从 Firebase 数据库中检索所有花瓶?

javascript - 如何从 Firebase 存储中删除 Vue.js 组件图像?

ios - 如何从 Today View Widget 引用 AppDelegate?

ios - 扩展 Swift 数组以复制 indexOfObject 函数

ios - 自动调整 UITableView 中嵌入的 UICollectionView 单元格大小不起作用