1

I've found several places showing how to subclass UIApplication.openURL which is called when a user taps a hyperlink in a UITextView. However, I'm finding that this is not called when they tap a mailto link, and I only need to override mailto links. My app includes an email client, and since Apple will not allow me to make my app the "default" email client, I at least want mailto links inside my own program to use my app for sending email.

I first tried using a UIWebView instead, which did allow me to do this, however that had some display issues (I'm just displaying plain-text and it doesn't look/work as nice as the UITextView for that).

I have also tried overriding UIApplication.canShowURL but it is never called, not even for http: links. I've tried subclassing and also "Swizzling", both give same results.

eselk
  • 6,764
  • 7
  • 60
  • 93
  • You can probably look into the following for a solution: http://stackoverflow.com/questions/4403992/possible-to-handle-your-own-http-url-schemes-in-ios – kineticfocus Nov 05 '12 at 19:10

1 Answers1

2

Based on info I found here Possible to handle your own http URL schemes in iOS?, from the comment by kineticfocus, I ended up with:

Register for a custom URL scheme http://mobiledevelopertips.com/cocoa/launching-your-own-application-via-a-custom-url-scheme.html.

Before displaying my text in the UITextView, find each valid email address and mailto: URL and convert to my custom URL scheme. Example conversions:

example@sample.com -> myapp://example@sample.com

mailto:example@sample.com -> myapp://example@sample.com

This isn't ideal because it makes the text harder to read due to the conversion (not so much for the mailto: URLs but for the plain email addresses in the text it does), but was the best I could find without going to a UIWebView.

I was impressed that the UITextView supports custom URL schemes -- In the Windows world I've always wished the RICHEDIT window class would support that, but it doesn't.

Only posting this as an answer instead of reporting my question as a duplicate because most everything else I've found is not related to UITextView, they are either using UIWebView or just want to invoke their app from another app or website.

Community
  • 1
  • 1
eselk
  • 6,764
  • 7
  • 60
  • 93