【问题标题】:Firestack react-native exception 'Failed to get default FIRDatabase instance'Firestack react-native 异常'无法获取默认 FIRDatabase 实例'
【发布时间】:2016-08-31 10:57:23
【问题描述】:

我学习了以下教程:

https://www.fullstackreact.com/articles/announcing-firestack-for-firebase/

我做了所有的步骤。

我还创建了一个 Google Firebase 项目,并将 Web 设置中的配置参数添加到 Firestack 的配置对象中。

当我尝试运行应用程序时,我收到以下错误:

Exception '获取默认 FIRDatabase 实例失败。必须在使用 FIRDatabase 之前调用 FIRApp.configure()。在使用 params ("/events", "child_added", 7) 调用目标 FirestackDatabase 之前被抛出

我正在使用 firebase v3.3.0、react-native-firestack v2.2.1 和 react v15.3.1

我不知道为什么会这样

【问题讨论】:

    标签: ios objective-c xcode firebase react-native


    【解决方案1】:

    在您提供的用于在应用程序委托中添加数据库配置的教程链接中,我没有看到任何地方。在 Swift/Obj-C 中打开应用委托,导入 Firebase,并将 FIRApp.configure() 添加到 didFinishLaunchingWithOptions

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    
        FIRApp.configure()
        return true
    }
    

    编辑:使用 firestack 配置应用程序是不同的。您可以使用以下代码配置应用,而不是 FIRapp.configure()。

    const firestack = new Firestack()
    firestack.configure().then(() => console.log("Project configured and ready to boot"));
    

    【讨论】:

    • 是否应该手动添加 Firebase SDK 以便可以导入 Firebase?或者我应该使用 Firestack 框架中已经存在的东西吗?如果我使用 Firestack 中的那个,我应该怎么做?对不起,如果这听起来很愚蠢,但我以前没有使用 XCode 或 Objective-C 的经验。
    • Firestack 应该在设置过程中链接了 firebase 的所有要求。尝试在您的应用委托中导入 Firebase,看看是否可以添加上述行。如果不是,我建议避免手动添加 Firebase SDK。特别是如果您对 xcode 没有太多经验,这会很痛苦。而是使用 cocoapods。 Firebase 有一个很好的参考来设置他们的 iOS 开发工具包。 firebase.google.com/docs/ios/setup
    【解决方案2】:

    对我来说,这个错误是因为我在配置之前调用了“set persistent”:

    const firestack = new Firestack();
    
    firestack.configure().then(() => {
        firestack.database.setPersistence(true);
    });
    

    【讨论】:

      猜你喜欢
      • 2019-12-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-06
      • 2021-09-18
      • 2012-02-12
      • 1970-01-01
      相关资源
      最近更新 更多