Override or customize the default behavior of "longpress mailto:"

I'm currently developing an email application and want all mailto links to open through my application, and not the default Apple Mail application.

For example, I have a link like this

<a href="mailto:email@example.com\>mailto_test</a>

in a UIWebView or UITextView (it doesn't matter which one has similar behavior).

When I disable this link, iOS will show UIAlertController with three parameters:

enter image description here

The first option, New Message, will open the Mail app by default. So my question is how to override this behavior? How can I get this feature to run my own email application?

, - iOS Gmail. Gmail , , , .

+4
3

. textView(_:shouldInteractWith:in:interaction:). - .presentActions. false . .actionSheet, , , , .

+4

, , .

UITextView:

, UITextView textView, attributeString -

<a href="mailto:email@example.com\>mailto_test</a>

documentType - html. :

let textView = UITextView(frame: view.bounds)
textView.frame.origin.y += 100

let attrStr = try! NSAttributedString(
    data: "<a href=\"mailto:email@example.com\">mailto_test</a>".data(using: .utf8, allowLossyConversion: true)!,
    options:[.documentType: NSAttributedString.DocumentType.html],
    documentAttributes: nil)

textView.attributedText = attrStr
view.addSubview(textView)

, mailto_test . delegate textView click.

textView.isEditable = false
textView.dataDetectorTypes = .link
textView.delegate = self

:

func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool {
    print(URL)
    return false
}

, , . URL- - .

+1

- , ? , URL- .

enter image description here

, URL ( Apple)

:

0

Source: https://habr.com/ru/post/1687236/


All Articles