-1

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.

AtulParmar
  • 4,358
  • 1
  • 24
  • 45
  • 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 Answers3

1

Unchecked "Link" and "Address" flag to disable URLs which exist in UItextview, see the following.

enter image description here

AtulParmar
  • 4,358
  • 1
  • 24
  • 45
0

You can use this code:

textView.dataDetectorTypes = []
qtngo
  • 1,594
  • 1
  • 11
  • 13
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