Search code examples
iosiphonecocoa-touchuiwebviewmailto

Readymade solution to parse mailto URLs in Cocoa?


I have a UIWebView in an iPhone app and want to intercept structured mailto-URLs like mailto:[email protected]?subject=foo&body=bar in order to display a MFMailComposeViewController inside the app instead of handing over the URL to Mail.app.

Now it would be great if all properties of MFMailComposeViewController would be automatically set according to the mailto URL. Unfortunately, MFMailComposeViewController does not accept a mailto URL but requires to set the individual properties.

NSURL apparently is not of great help either. Are you aware any existing code so that I don't have to write the parser code? ;)


Solution

  • Wrote my own solution: https://gist.github.com/667952 It's a bit ugly and probably not 100% foolproof in terms of RFC support, but as long as the syntax of the mailto URLs is under your own control, it works fine.