JSQMessagesViewController发送位置未加载

时间:2018-06-10 17:30:09

标签: swift jsqmessagesviewcontroller

注意:这不是此问题的副本:send location using JSQLocationMediaItem

我已经尝试使用该页面上答案中的代码,结果没有改变。我的错误与该问题上显示的错误相同,但该问题的解决方案对我没有帮助。

这是我的代码:

let loc: JSQLocationMediaItem = JSQLocationMediaItem()
// Assume that cllocation is a proppert location.
// I have already confirmed this by printing cllocation.location to the console.
loc.setLocation(cllocation, withCompletionHandler: {
    // This is a incoming message
    loc.appliesMediaViewMaskAsOutgoing = false
    // Adding the JSQMessage to my array. Assume that all information given is correct.
    self.JSQMessages[self.JSQMessages.count - 1].append(JSQMessage(senderId: "2", senderDisplayName: self.chatWithUser.username, date: message.messageDate, media: loc))
    self.collectionView.reloadData()
})

发生的事情是我的聊天气泡显示好像正在接收,但它中间有一个UIActivityIndicatorView,它只会永远显示出来。它实际上从未加载地图。

1 个答案:

答案 0 :(得分:0)

我通过将此答案Show LocationMediaItem in JSQMessagesViewController中的代码转换为swift来找到答案。对于今后需要它的人来说,我的代码现在看起来像这样:

let loc: JSQLocationMediaItem = JSQLocationMediaItem()
loc.appliesMediaViewMaskAsOutgoing = false
self.JSQMessages[self.JSQMessages.count - 1].append(JSQMessage(senderId: "2", senderDisplayName: self.chatWithUser.username, date: message.messageDate, media: loc))
loc.setLocation(cllocation, withCompletionHandler: {
    self.collectionView.reloadData()
    self.scrollToBottom(animated: true)
})