【发布时间】:2018-06-22 04:16:54
【问题描述】:
在第一次安装时,应用程序运行没有任何问题。
- 在启动画面检查登录状态。
- 用户未登录,导航到登录屏幕。
但unsubscribe() is not a function 错误显示并在应用程序最小化然后重新打开时卡在初始屏幕。这只发生在最小化 > 从全新安装和首次运行中恢复。
这意味着如果我从后台杀死应用程序并打开然后最小化然后恢复,它工作得很好。
这是我在 firebase 文档中使用的 checkLoginState 函数。我不确定这与react-native 或firebase 或react-native-firebase 或react-navigation 有关。知道如何调试和修复这个问题吗?
Handle the sign-in flow manually
function checkLoginState(event) {
if (event.authResponse) {
// User is signed-in Facebook.
var unsubscribe = firebase.auth().onAuthStateChanged(function(firebaseUser) {
unsubscribe();
// Check if we are already signed-in Firebase with the correct user.
if (!isUserEqual(event.authResponse, firebaseUser)) {
// Sign in user.
} else {
// User is already signed-in Firebase with the correct user.
}
});
} else {
// User is signed-out of Facebook.
firebase.auth().signOut();
}
}
更新
在全新安装 > 首次运行 > 最小化 > 恢复`,应用程序看起来像堆栈或什么。如果我使用 react-native reload 重新加载应用程序,我会在日志中得到这个。 componentDidmount 和 unmount 运行多次。每个最小化>恢复堆栈1。如果我杀死应用程序并重新打开,这个问题就消失了。请注意,这在物理设备和虚拟设备中都会发生。
更新 1
这主要与本机反应有关。 https://github.com/facebook/react-native/issues/12562
【问题讨论】:
-
我想它只发生在 Android 上,对吧?你会测试在你的 AndroidManifest.xml 上添加它,看看它是否修复了吗? `
-
是的 android 但不确定 ios。我尝试了您的解决方案,但仍然出现同样的错误。
-
尝试删除
var unsubscribe =并删除第5行。 -
@MattAft 我无法删除取消订阅,因为如果用户单击注销按钮,onAuthStateChanged 触发然后 facebook,firebase 用户将在 isUserEqual() 进行比较并立即登录用户。我用 firebase 文档链接更新了问题。
-
如果您设置了“SingleTask”,您的应用程序在进入后台时不应重新启动(不应进入 Splash)并通过按应用程序图标返回。我想确保您的应用能够做到这一点。
标签: firebase react-native firebase-authentication react-navigation react-native-firebase