onSnapshot appears to stop working after a period of time

时间:2019-04-08 12:57:06

标签: firebase react-native google-cloud-firestore react-native-firebase

I am using firestore onSnapshot methods in a React Native app on several different sets of data in my app, and for the most part they all appear to work fine. However, after a period of time, perhaps after the app is put into background and re-awakened, the onSnapshot methods stop updating the data.

It is as if they have switched off. Sometimes they seem to stop working just after a period of time, without the app being backgrounded.

If I call the methods again then they start working again, but that seems to defeat the object of using them, I may as well just use normal get() methods and call them when I need.

Surely someone else has experienced this and can help?

1 个答案:

答案 0 :(得分:0)

发生错误时,Firebase将调用(可选)第二个回调,您可以将其传递给onSnapshot或简单的get之类的函数。例如

const coleccionRef = database.ref('test');
coleccionRef.on('value', snapshot => {
    snapshot.val();
}, error => {
    console.error(error);
});

您可以检查该错误以了解问题所在。