在iOS Swift中检索Firebase问题中的聊天消息

时间:2019-05-31 11:07:18

标签: ios swift firebase firebase-realtime-database

enter image description here

我正在使用Firebase聊天应用程序。当我尝试发送消息时。比消息,表有价值,但没有更新聊天消息表。我在此[https://github.com/DevSurya/ChatApp-Swift-And-Firebase]中引用此链接。

当我运行演示时,它可以正常工作。在我的情况下,Observe方法未调用并且collectionview不刷新

private func sendMessageWithProperty(_ property: [String: AnyObject]){
        let ref = Database.database().reference().child("messages")
        let childRef = ref.childByAutoId()
        let toId = user!.id!
        let fromId = Auth.auth().currentUser!.uid
        let timeStamp = NSNumber.init(value: Date().timeIntervalSince1970)
        var values: [String : AnyObject] = ["toId":toId as AnyObject, "fromId":fromId as AnyObject, "timeStamp":timeStamp]

        values = values.merged(with: property)

        childRef.updateChildValues(values)

        childRef.updateChildValues(values) { (error, ref) in
            if error != nil {
                print(error!)
                return
            }
            self.inputTextField.text = nil
            let userMessageRef = Database.database().reference().child("user-messages").child(fromId).child(toId)
            let messageId = childRef.key
            userMessageRef.updateChildValues([messageId: 1])

            let recipentUserMessageRef = Database.database().reference().child("user-messages").child(toId).child(fromId)
            recipentUserMessageRef.updateChildValues([messageId: 1])
        }
    }

0 个答案:

没有答案