The Distant Past

Before 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.

This 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:

if MFMailComposeViewController.canSendMail() {
	let mailController = MFMailComposeViewController(rootViewController: self)
	mailController.setSubject("Test Subject")
	mailController.setToRecipients(["mail@test.com"])
	mailController.mailComposeDelegate = self
	present(mailController, animated: true, completion: nil)
}

Today

As 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:

if UIApplication.shared.canOpenURL(url) {
	UIApplication.shared.open(url, options: [.universalLinksOnly : false]) { (success) in
		// Handle success/failure
	}
}

Unlike 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.

A feature request for iOS 15: default mail apps should have their own MFMailComposeViewController equivalent.