Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firestore Adding Document || Offline || Callback [duplicate]

Not getting the callback on adding document in the collection during offline. Its working good in online mode.

However, the document is getting added, and the listeners listening to the collection is getting the added document snapshot.

let database = Firestore.firestore()
    let data = prepareRawDataFromObject(model)
    if let data = data {
        printLog("🔵 Collection: \(collection)🔵")
        printLog("🛡 Data Request: \(String(describing: data)) 🛡")
        var documentRef: DocumentReference? = nil
        documentRef = database.collection("collection").addDocument(data: data) { (error) in
            if let error = error {
                failure()
                printLog("🆘 Adding Document \(collection): \(error.localizedDescription) 🆘")
            } else {
                printLog("✅ Document Added successfully...✅")
                success(documentRef!.documentID)
            }
        }
    }
like image 260
Priyam Dutta Avatar asked Apr 19 '26 14:04

Priyam Dutta


1 Answers

Neither the success listener nor the failure listener will be called if your device cannot reach Firestore backend. The success/failure listeners will only be called once the data is committed to, or rejected by the Firebase servers. This is the reason you aren't getting anything while your device is offline and it is working properly when the device is online.

So if the listener will still exist when the write operation will complete, with other words when the device is back online, then it will be invoked.

like image 137
Alex Mamo Avatar answered Apr 22 '26 07:04

Alex Mamo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!