Hi, embedded links alone or within/at the end of a paragraph do not result in delegate method func didSelectURL(_ url: URL) getting called to handle tapping that link. Any suggestions?
Hey @zoufishanmehdi,
Two other questions:
messageCellDelegate of MessagesCollectionView?Can you give me an example of the links or text that this occurs with?
I have set messageCellDelegate of MessagesCollectionView. After I get data from network request, I convert the html string to nsattributed string and append to messages array. When I click on the embedded link i.e. Click this func didTapMessage(in cell: MessageCollectionViewCell) gets called and I can't handle the url here without a reference to the link. If it's a regular link i.e. https://www.cnn.com/, it gets detected in func didSelectURL(_ url: URL) and works fine.
@zoufishanmehdi 馃 We use Apple default NSDataDetector to check types, so .url can only work on that the text itself is url.
@SD10 We maybe can use some substitution ways to enhancement detector capacity.
I definitely think we can make improvements to the MessageLabel class in a later version. It needs some love 鉂わ笍
I did some research on this topic and apparently by using an UILabel for messages you also miss out on any out-of-the-box commands for links, phone numbers etc. if you tap on it (e.g. call, add to address book etc.). This seems to work only with a UITextView.
@SD10 @zhongwuzw What is your current opinion on this?
If one would want to add support for embedded links to MessageKit, what would be your approach of choice? Ideally, supporting these extra options when tapping on data would also be nice. Is there any way of achieving this without using an UITextView? And what is the reasoning behind using UILabel instead of an UITextView? I guess it is performance-related?
@Luke47 , MessageKit needs to enhance for these detectors.
A solution for embedded links, my opinion is we needs to use NSAttributedString for render, we maybe can provide a delegate that show the touch point or its character index which the user pressed, after that we can figure out wether or not to respond.
And what is the reasoning behind using UILabel instead of an UITextView?
Yep, it's performance-related based on the result that talking to @SD10.
@Luke47 @zhongwuzw Jesse also had some sage advice early on regarding UITextView vs UILabel. See here: https://github.com/MessageKit/MessageKit/issues/2
A solution for embedded links, my opinion is we needs to use NSAttributedString for render, we maybe can provide a delegate that show the touch point or its character index which the user pressed, after that we can figure out wether or not to respond.
I'm actually implementing exactly this right now, in my MessagesViewController subclass. I'd be happy to port the changes and/or update the way the DataDetector scans an attributed string for detector types. (One thought I had was that in addition to scanning the string itself, we could enumerate the attributed string's attributes and check for a match there as well - then add an entry to the detected array (the enumeration would give you an NSAttributedStringKey & range - NSLinkAttributeName would map to .url, for example.)
@austinwright , yes, I agree that. We can add this and also provide a delegate for custom.
@SD10 - Is there any update on handling Embedded link. We're actually stuck in this thing, Any suggestion to help us expand this feature - I'm open to do it (provided) I need access to edit the framework to add a custom delegate. or If you can provide any work around for this, it would be highly appreciable.
I've opened a PR to our fork of MessageKit that might be of use.
It adds support for embedded NSLinks as @zoufishanmehdi describes, and avoids changing anything fundamental about how layout is performed.
It's a little rough but it does the job; hopefully I can tidy it up and contribute back to the project if it proves useful 馃檪
monzo#1: Add support for embedded NSLinks for .url DetectorType
@jnic That looks like a valid solution to me 馃憤 Feel free to submit a PR
This will be fixed in MessageKit 1.1 by #815
Would be great to see some example code on how this function should be implemented. didTapMessage still appears to overwrite didSelectURL for me when I use custom text as opposed to displaying the whole link. I tried looking all around the website, but saw very little documentation. Any help would be greatly appreciated!
Hey @gastonar please open a new issue with your question and any details you can provide, you're more likely to get help that way. Thanks! 鉂わ笍