I want to stop my app from opening a url that may be present in my textview when I populate it with the data I get from api.
Asked
Active
Viewed 331 times
-1
-
check this link https://stackoverflow.com/questions/36198299/uitextview-disable-selection-allow-links – Uma Madhavi Feb 27 '19 at 07:02
-
This is not what i want, i basically want to know when and what url my app is trying and make a decision whether we want to allow or not. – Harish Saini Mar 18 '19 at 09:07
3 Answers
0
If you implement textView(_:shouldInteractWith:in:interaction:) of the UITextViewDelegate you can control whether the URL should be opened or not.
Just return false
if you don't want any URL to be handled:
func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool {
return false
}

d.felber
- 5,288
- 1
- 21
- 36