UITextView
allows tappable attributedText
based hyperlinks.The user interaction with the link can be intercepted by implementing the delegate method. textView:shouldInteractWithURL:in:
which has two variations, for iOS 10 and one for iOS 9 as below.
// For iOS 9 and below.
@available(iOS, deprecated=10.0)
func textView(textView: UITextView, shouldInteractWith URL: NSURL, in characterRange: NSRange) -> Bool {
// Present UIWebView here...
return false
}
@available(iOS 10.0, *)
func textView(textView: UITextView, shouldInteractWithURL URL: NSURL, inRange characterRange: NSRange, interaction: UITextItemInteraction) -> Bool {
// Present UIWebView here...
return false
}
The callback for iOS 10 works when running app in iOS 10
, but when in iOS 9, the other callback never gets called. It directly launches safari.
I've tried various combinations of @available
attribute but nothing worked. The delegate simply never gets called for iOS 9
.
The app's Deployment Target
is iOS 9
using Xcode 8
while Base SDK
is iOS 10.2
.
Update I'm using Swift 2.3