Firestore fails to retrieve data after reconnecting to the Internet

后端 未结 4 694
臣服心动
臣服心动 2021-02-02 12:44

I\'m using Firestore with the Android SDK (11.6.2) and I\'m hitting an exception when my device was offline and reconnects to the Internet.

When requesting a document, f

4条回答
  •  梦谈多话
    2021-02-02 13:04

    From the official documentation:

    To use offline persistence, you don't need to make any changes to the code that you use to access Cloud Firestore data. With offline persistence enabled, the Cloud Firestore client library automatically manages online and offline data access and synchronizes local data when the device is back online.

    When you initialize Cloud Firestore, you can enable or disable offline persistence. So, when using the following line of code:

    val firestoreSettings = FirebaseFirestoreSettings.Builder()
        .setPersistenceEnabled(false)
        .build()
    

    You actually set the persistence to false, you are disabling this feature. To solve this, just remove this line of code. Firestore has .setPersistenceEnabled(true) by default.

提交回复
热议问题