短信后带有媒体的 JSQ 消息
JSQMessage with media after text message's
我正在尝试使用 JSQMessagesViewController 加载消息。
但是 mediaMessages 最后添加到数组中,尽管它们不应该。
图像应位于文本消息之间,但它们最后出现。
我想我需要为图像或类似的东西添加一个空气泡。
JSQMessage with media
此 mediaMessage 必须介于 2 和 3 message
之间
我的代码:
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()
}
}
}
})
我正在尝试使用 JSQMessagesViewController 加载消息。 但是 mediaMessages 最后添加到数组中,尽管它们不应该。 图像应位于文本消息之间,但它们最后出现。 我想我需要为图像或类似的东西添加一个空气泡。
JSQMessage with media 此 mediaMessage 必须介于 2 和 3 message
之间我的代码:
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()
}
}
}
})