【问题标题】:NativeScript Firebase already initializedNativeScript Firebase 已初始化
【发布时间】:2019-08-06 01:19:59
【问题描述】:

我在我的应用中使用 Firebase,我注意到当我主动进行更改并且 LiveSync 更新应用时,它有时会显示“firebase.init 错误:Firebase 已初始化”。当更改不会触发整个应用程序重新启动(例如 html 文件)时,就会发生这种情况。它完全打乱了我当前的身份验证状态并强制我重新启动应用程序。

有什么方法可以捕捉或防止这种情况发生吗?我可以尝试为它制作一个演示应用程序,但我觉得这可能已经发生在某人身上了。

我只是使用标准的firebase.init,如我的 app.component 中的文档所示,没有什么特别或不同的。

【问题讨论】:

标签: nativescript angular2-nativescript nativescript-plugin nativescript-firebase


【解决方案1】:

不要在 App.component 的 ngOnit 上使用,而是尝试在 app launch 事件上初始化 firebase。

applicationOn(launchEvent, (args: LaunchEventData) => {
    firebase.init({
   // Optionally pass in properties for database, authentication and cloud messaging,
  // see their respective docs.
  }).then(
function () {
  console.log("firebase.init done");
},
function (error) {
  console.log("firebase.init error: " + error);
}
 );
});

【讨论】:

  • 我能够通过在 app.component firebase.addAuthStateListener(listener) 中使用分离的 onAuthStateChanged 并测试 firebase.initialized 是否为真来实现这一点,然后我使用 firebase.getCurrentUser() 手动获取当前用户。迂回的方式,但它的工作原理。
猜你喜欢
  • 1970-01-01
  • 2021-07-27
  • 2019-08-20
  • 2021-06-21
  • 2020-10-10
  • 2020-12-25
  • 2021-01-02
  • 2017-03-26
  • 2022-10-16
相关资源
最近更新 更多