Description of the initial situation:
I have enabled data persistence on Firestore by following the documentation: https://firebase.google.com/docs/firestore/manage-data/enable-offline It works, when I make an offline write request my listener receives the information and I can display it locally. When I get back to the connection the data are well synchronized.
Description of the problem:
- I open the application on android and go offline.
- I make an offline modification to firestore DB.
- I kill my application.
- I reconnect, still offline.
- I try to read the data from the cache.
- One time out of two : I get the data, it works perfectly.
- The other time : The cache is like empty and doesn't return any data.
When I say one out of two times, it means that when I kill the app and don't get the data, if I kill it again and open it, I get the data again (without being in online mode). If I do it again, I lose them. (And this boucle is infinite)
The request to get the data is the same each time.
PS : On PWA version, it work every time
Question: How do I get the data from the cache every time? Did I miss a step?
1条答案
按热度按时间2lpgd9681#
我终于找到了解决办法:
我使用AngularFire以这种方式启用持久性(在
app.module.ts
中):必须启用选项(synchronizeTabs)。我的猜测是,应用程序没有被Android完全杀死,因此在下次打开时被算作第二个选项卡。
接下来,我这样使用它:对于每个请求,我检查用户是否在线,如果不在线,我切换到离线模式: