{
"$type": "site.standard.document",
"path": "/2021-01-08-the-diminishing-utility-of-mfmailcomposeviewcontroller/",
"publishedAt": "2021-01-08T14:22:00.000Z",
"site": "at://did:plc:ex23caczr45rodrfcxrwps6h/site.standard.publication/self",
"tags": [
"code"
],
"textContent": "The Distant Past\n\nBefore iOS 14, the default email app on iOS was Mail. Of course, you could have had other email apps installed, but they’d never be the app used by the system when tapping on an email address. You’d always end up in Mail.\n\nThis made things easy for developers. If you wanted give users the ability to send emails from within your app, you’d use MFMailComposeViewController. Implementation was easy:\n\nif MFMailComposeViewController.canSendMail() {\nlet mailController = MFMailComposeViewController(rootViewController: self)\nmailController.setSubject(\"Test Subject\")\nmailController.setToRecipients([\"mail@test.com\"])\nmailController.mailComposeDelegate = self\npresent(mailController, animated: true, completion: nil)\n}\n\nToday\n\nAs a developer, I want to respect the user’s choice of email app, whether it’s Mail, Edison, Gmail, Outlook, or Hey. To do that, I can’t use MFMailComposeViewController. Instead, I have to add mailto to the LSApplicationQueriesSchemes key in Info.plist and then, when the user wants to send an email, use this code:\n\nif UIApplication.shared.canOpenURL(url) {\nUIApplication.shared.open(url, options: [.universalLinksOnly : false]) { (success) in\n// Handle success/failure\n}\n}\n\nUnlike MFMailComposeViewController, this approach sends the user to their choice of email app and, at the same time, closes the source app. It’s not ideal.\n\nA feature request for iOS 15: default mail apps should have their own MFMailComposeViewController equivalent.",
"title": "The Diminishing Utility of MFMailComposeViewController"
}