swiftjsqmessagesviewcontroller

JSQMessagesViewController sending location not loading


Note: This is not a copy of this question: send location using JSQLocationMediaItem

I have already tried using the code from the answer on that page, and the results did not change. My error is the same as the error shown on that question, but the solution from that question did not help me.

Here is my code:

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()
})

What happens is that my chat bubble shows as if it is recieving, but it has a UIActivityIndicatorView in the middle, and it just shows that forever. It never actually loads the map.


Solution

  • I found an answer to this, by converting code from this answer Show LocationMediaItem in JSQMessagesViewController to swift. My code now looks like this for anyone who needs it in the future:

    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)
    })