ios – How can I present a long-press menu for a link in a UITextView that is a custom URL scheme of mine?

0
62


In my app I have a UITextView where I parse the text, detect references to content in my app, and add hyperlinks to that content via NSAttributedString / NSLinkAttributeName. Right now I have it set up so I can handle taps on those links via the UITextViewDelegate method textView:shouldInteractWithURL:inRange:interaction: and show a popover with the relevant content.

I notice, though, that for URLs that the system understands, if you long-press on a link in a text view, it gives you options for that URL type, and even a preview if it’s a web link or something that can easily be previewed. My question: how do I provide custom actions and/or custom previews for my own URLs?