gpt4 book ai didi

swift - Firebase Child By AutoID 与多个用户?

转载 作者:搜寻专家 更新时间:2023-11-01 06:27:47 30 4
gpt4 key购买 nike

目前,我正在将 firebase 用于消息传递应用程序。对于消息,我使用 childByAutoID() 来创建新消息。如果两个人同时创建一条消息,ID会创建正确吗?

 let messageConnection = Database.database().reference().child("messages").child(convoID!).childByAutoId()
messageConnection.updateChildValues(["content" : messageText ?? "incomplete", "sender": userHash, "time": time], withCompletionBlock: { error, ref in

if error != nil{
print("ERROR")
}
else{
let conversationRef = Database.database().reference().child("conversations").child(self.convoID!)
conversationRef.updateChildValues(["last_message" : messageText!,"last_message_time":time])
textField.text = ""
}

})

最佳答案

我不确定这里的“正确”对你意味着什么。

但是当两个应用程序实例同时调用 childByAutoId() 时,它们仍然会获得一个唯一的 ID。 ID 在统计上保证是唯一的,并包含足够数量的随机位以确保这一点。

要了解有关这些推送 ID 的更多信息,请阅读 The 2^120 Ways to Ensure Unique Identifiers .

关于swift - Firebase Child By AutoID 与多个用户?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51622407/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com