<!--
{
  "availability" : [
    "iOS: 7.0.0 - 10.0.0",
    "iPadOS: 7.0.0 - 10.0.0",
    "macCatalyst: 13.1.0 - 13.1.0",
    "tvOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UITextViewDelegate/textView(_:shouldInteractWith:in:)-98tho",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(pl)UITextViewDelegate(im)textView:shouldInteractWithURL:inRange:"
  },
  "title" : "textView(_:shouldInteractWith:in:)"
}
-->

# textView(_:shouldInteractWith:in:)

Asks the delegate whether the specified text view allows user interaction with the specified URL in the specified range of text.

```
optional func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange) -> Bool
```

## Parameters

`textView`

The text view containing the text attachment.

`URL`

The URL to be processed.

`characterRange`

The character range containing the URL.

## Return Value

<doc://com.apple.documentation/documentation/Swift/true> if interaction with the URL should be allowed; <doc://com.apple.documentation/documentation/Swift/false> if interaction should not be allowed.

## Discussion

The text view calls this method if the user taps or long-presses the URL link. Implementation of this method is optional. By default, the text view opens the application responsible for handling the URL type and passes it the URL. You can use this method to trigger an alternative action, such as displaying the web content at the URL in a web view within the current application.

> Important:
> Links in text views are interactive only if the text view is selectable but noneditable. That is, if the value of the `UITextView` ``doc://com.apple.uikit/documentation/UIKit/UITextView/isSelectable`` property is <doc://com.apple.documentation/documentation/Swift/true> and the ``doc://com.apple.uikit/documentation/UIKit/UITextView/isEditable`` property is <doc://com.apple.documentation/documentation/Swift/false>.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)