diff --git a/iphone/Maps/UI/Help/AboutController/AboutController.swift b/iphone/Maps/UI/Help/AboutController/AboutController.swift index 6ab0665ec3..db1ca8263f 100644 --- a/iphone/Maps/UI/Help/AboutController/AboutController.swift +++ b/iphone/Maps/UI/Help/AboutController/AboutController.swift @@ -481,6 +481,20 @@ private extension AboutController { } return false } + + func openDefaultMailApp(subject: String, body: String, recipients: [String]) -> Bool { + var components = URLComponents(string: "mailto:\(recipients.joined(separator: ";"))") + components?.queryItems = [ + URLQueryItem(name: "subject", value: subject), + URLQueryItem(name: "body", value: body.replacingOccurrences(of: "\n", with: "\r\n")), + ] + + if let url = components?.url, UIApplication.shared.canOpenURL(url) { + UIApplication.shared.open(url) + return true + } + return false + } let subject = emailSubject(subject: header) let body = emailBody() @@ -491,15 +505,10 @@ private extension AboutController { openOutlook(subject: subject, body: body, recipients: toRecipients))) { return } + // From iOS 14, it is possible to change the default mail app, and mailto should open a default mail app. - if MWMMailViewController.canSendMail() { - let vc = MWMMailViewController() - vc.mailComposeDelegate = self - vc.setSubject(subject) - vc.setMessageBody(body, isHTML:false) - vc.setToRecipients(toRecipients) - vc.navigationBar.tintColor = UIColor.whitePrimaryText() - self.present(vc, animated: true, completion:nil) + if openDefaultMailApp(subject: subject, body: body, recipients: toRecipients) { + return } else { let text = String(format:L("email_error_body"), toRecipients.joined(separator: ";")) let alert = UIAlertController(title: L("email_error_title"), message: text, preferredStyle: .alert) @@ -510,13 +519,6 @@ private extension AboutController { } } -// MARK: - MFMailComposeViewControllerDelegate -extension AboutController: MFMailComposeViewControllerDelegate { - func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) { - self.dismiss(animated: true, completion: nil) - } -} - // MARK: - UIStackView + AddArrangedSubviewWithSeparator private extension UIStackView { func addArrangedSubviewWithSeparator(_ view: UIView) {