1

I'm trying to open url from messages embedded in an NSAttributedString. I'm using the latest version of MessageKit. I'm using the function didSelectURL, but it doesn't seem to reach that part of the code. I came across this solution, but I wanted to follow up with regards to how to set up MessageLabelDelegate. Just like in the linked solution, I have implemented the delegate methods detectorAttributes and enabledDetectors.

I currently have MessageLabelDelegate set up as an extension to my ViewController, but it never seems to reach those methods.

extension ChatViewController:MessageLabelDelegate {

func didSelectURL(_url: URL) {
// .. open URL
}

}

It seems to be getting overwritten by the method didTapMessage in the MessageCellDelegate extension. I tried going through the example code in the MessageKit repo, but still unclear as to how it's meant to be set up or what I'm doing wrong.

UPDATE: The problem was the way I was declaring the NSAttributedString. I was setting its value as a string instead of a URL.

gastonar
  • 11
  • 2

1 Answers1

0

The MessageCellDelegate implements the the MessageLabelDelegate so you need to make sure that the messagesCollectionView.messageCellDelegate is set to the ChatViewController and that the ChatViewController has an extension for MessageCellDelegate where you can put your didSelectURL

public protocol MessageCellDelegate: MessageLabelDelegate {
bryan
  • 170
  • 2
  • 8