Show LocationMediaItem in JSQMessagesViewController

我是研究僧i 提交于 2019-12-06 05:50:16

Was having the same issue as you and was able to make it work.

The trick was not to set the location right on the LocationMediaItem constructor, leave it null then use the method SetLocation which receives the location and a handle as parameters.

var itemLoationItem = new LocationMediaItem ();
itemLoationItem.AppliesMediaViewMaskAsOutgoing = true;
Messages.Add (Message.Create (SenderId, SenderDisplayName, itemLoationItem));
itemLoationItem.SetLocation (new CLLocation (lat, long), HandleLocationMediaItemCompletionBlock);

In the handle just reload the data

void HandleLocationMediaItemCompletionBlock ()
{
    this.CollectionView.ReloadData ();
}

Note: Avoid creating the Message object in GetMessageData as this method is called every time the Collectionview is reloaded. You should handle the Message creation when receiving the message or when sending it and add it to the collection of messages then in this method you just return the object from the collection.

public override IMessageData GetMessageData (MessagesCollectionView collectionView, NSIndexPath indexPath)
{
    return Messages [indexPath.Row];
}

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!