3

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)
            }
        }
    }
Priyam Dutta
  • 702
  • 5
  • 19
  • See https://stackoverflow.com/questions/52648399/firestore-adding-document-offline-callback, https://stackoverflow.com/questions/47843218/offline-issue-with-firestore-vs-firebase?rq=1 (both linked from the related questions) and https://stackoverflow.com/questions/46672630/addoncompletelistener-not-called-offline-with-cloud-firestore/46674020 – Frank van Puffelen Oct 04 '18 at 14:10

1 Answers1

1

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.

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193