簡體   English   中英

Firestore似乎無法離線工作

[英]Firestore does not work seem to work offline

我正在嘗試使用Firestore創建漸進式Web應用程序。 當計算機處於聯機狀態時,Web應用程序可以正常運行,但在脫機狀態下則無法運行。

我已啟用Firestore離線持久性,如下所示:

firebase.firestore().settings({ timestampsInSnapshots: true });
firebase.firestore().enablePersistence().then(() => {
    this.db = firebase.firestore();
});

如果計算機脫機時運行該應用程序,則會出現以下錯誤。

[2018-10-23T07:15:24.406Z]  @firebase/firestore: Firestore (5.5.0): Could not reach Cloud Firestore backend. Connection failed 1 times. Most recent error: FirebaseError: [code=unavailable]: The operation could not be completed
This typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until it is able to successfully connect to the backend.

嘗試從Firestore數據庫獲取文檔失敗,並出現錯誤

Uncaught (in promise) Error: Failed to get document because the client is offline.

我了解這兩個錯誤在技術上都是正確的。 但是,由於啟用了離線持久性,難道不會發生這些錯誤嗎?

獲取離線數據:如果在設備離線時獲取文檔,Cloud Firestore將從緩存中返回數據。 如果緩存不包含該文檔的數據,或者該文檔不存在,則get調用將返回錯誤。

查詢脫機數據:查詢具有脫機持久性。 您可以通過直接獲取或通過偵聽來檢索查詢的結果,如前幾節所述。 您還可以在設備離線時對本地保留的數據創建新查詢,但是這些查詢最初只會針對緩存的文檔運行。

離線持久性並不意味着您的客戶可以在沒有互聯網的情況下與Firestore進行通信,這意味着,例如,一旦再次建立互聯網連接,他所做的更改便會提交給相關文檔。

考慮為用戶緩存相關文件以在一定程度上使用離線PWA。

有關離線使用它的更多信息

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM