2

Firebase實時數據庫具有可以手動管理連接的功能goOffline,goOnline。但是,Firestore沒有這些方法。Cloud Firestore沒有'goOffline','goOnline'方法。 (Android)

當設備與服務器失去連接時,Firestore是否會返回類似NETWORK_ERROR的異常?如果沒有,當設備無法連接到互聯網並重新連接時,如何手動管理Firestore連接。 (例如飛行模式,壞的wifi)

在我的情況下,我不使用persistence mode

回答

1

當 設備丟失與服務器的連接時,Firestore是否會返回類似NETWORK_ERROR的異常?

你必須使用addOnFailureListener它採用OnFailureListener可以只是給你一個Exception對象通過getCausegetMessage查找異常背後的原因或消息,並進一步可以申請串支票喜歡含有等覈實原因,但目前尚並非FirebaseFirestore提供的標準方式。

當設備無法連接到互聯網並重新連接時,如何手動管理Firestore連接。 (例如Airplane mode, Bad wifi

You can check the connectivity yourself also at desired places before executing firebase code

+0

感謝詳細答案。所以你的意思是'Firestore'改變了'onCancelled'的行爲[這在'實時數據庫'上不支持](https://stackoverflow.com/q/39021378/4729203)? – wonsuc

+1

實際上'Firestore'中沒有'onCancelled'方法。我在哪裏可以找到這個回調? – wonsuc

+0

@wonsuc你有兩種情況,第一,沒有網絡(你可以自己檢查連接,檢查第二部分中的鏈接),並在網絡錯誤的情況下,第一部分 –

相關問題