我尝试使用JSQMessagesViewController加载消息。 但是mediaMessages最后被添加到数组中,尽管它们不应该。 图像应该在文本消息之间,但它们最后出现。 我想我需要为图像或类似的东西添加一个空泡。
JSQMessage with media 此mediaMessage必须介于2到3之间
我的代码:
let query = Database.database().reference().child("chats").child(chatId!).queryLimited(toLast: 10)
_ = query.observe(.childAdded, with: { (snapshot) in
if let data = snapshot.value as? [String: AnyObject],
let id = data["userId"],
let name = self.chatName,
let text = data["content"]
{
if let image = data["image"] {
let storageKey = "images/" + self.chatId! + "/" + (image as! String)
let storageRef = Storage.storage().reference(withPath: storageKey)
storageRef.getData(maxSize: 1 * 1000 * 1000, completion: { (imageData, err) in
if err != nil {
print("Error with storage")
return
}
let imageMessage = UIImage(data: imageData!)
let mediaItem = JSQPhotoMediaItem(image: imageMessage)
if let message = JSQMessage(senderId: id as! String, displayName: name, media: mediaItem) {
self.messages.append(message)
self.finishReceivingMessage()
}
})
} else {
if let message = JSQMessage(senderId: id as! String, displayName: name, text: text as! String)
{
self.messages.append(message)
self.finishReceivingMessage()
}
}
}
})
答案 0 :(得分:0)