Firestore document creation fails without an error

孤者浪人 提交于 2020-12-15 06:41:55

问题


Edit3: Okay, it seems like it's an issue with Firebase, someone else tweeted about having the same issue. I also contacted support.

A piece of Swift code that handles creating documents suddenly stopped working. No errors are thrown, Firebase doesn't complain in the log and I can verify from the console that the document is not created, I can verify that the device has a healthy internet connection. I also disabled offline persistence for Firebase just to be sure.

When I try debugging it, the debugger jumps straight over the block that handles errors or successes, never running it (i.e. never finishing the Firestore request?).

Here is the code

    func createConversation(){
    let conversation : [String : Any] = ["owners" : [
        UserProfile().getProfile().uid!],
                                         "seeking" : true,
                                         "timestamp" : Timestamp(date: Date())
    ]

    var ref: DocumentReference? = nil
    ref = DB().firestore().collection("Conversations").addDocument(data: conversation){ err in
        if let err = err {
            print("Error creating a convo: \(err)")
        } else {
            print("Conversation created with ID: \(ref!.documentID)")
            StateMachine().action(a: .seekingStarted(ref!.documentID))


        }
        print("Conversation Creation finished")
    }
    let documentID = ref?.documentID
    print(ref.debugDescription)

}

I'm not sure how to approach this issue, any ideas?

Edit: Okay, the issue is not limited to this block of code, it looks like Firebase is not communicating with the servers. I've waited for more than 5min for the addDocument to return(with error or success) but that never happened.

I noticed that at the initiation of the App BoringSSL complains a bit but this is not new and I don't have problems with the other Firebase services, they work just fine - reading and creating data with no problems.

Edit2: Apparently I can fetch collections and documents from Firestore, the issue seems to be limited to document/collection creation.


回答1:


The document creation operation takes a little time, if you place the breakpoint inside the asynchronus completion block you will surely get an error or success.



来源:https://stackoverflow.com/questions/55019309/firestore-document-creation-fails-without-an-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!