From 6adc344b79e65aac6dd1753c66583315984d13b3 Mon Sep 17 00:00:00 2001 From: Valery Lozko Date: Sun, 7 Apr 2024 20:20:05 -0400 Subject: [PATCH 1/5] [ios] Add default email client support to about menu Signed-off-by: Valery Lozko --- .../UI/Help/AboutController/AboutController.swift | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/iphone/Maps/UI/Help/AboutController/AboutController.swift b/iphone/Maps/UI/Help/AboutController/AboutController.swift index 6ab0665ec3..8448c0a904 100644 --- a/iphone/Maps/UI/Help/AboutController/AboutController.swift +++ b/iphone/Maps/UI/Help/AboutController/AboutController.swift @@ -492,14 +492,13 @@ private extension AboutController { 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) + let encodedSubject = subject.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) ?? "" + let encodedBody = body.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) ?? "" + let correctEncodedBody = encodedBody.replacingOccurrences(of: "%0A", with: "%0D%0A") + + if let url = URL(string: "mailto:\(toRecipients)?subject=\(encodedSubject)&body=\(correctEncodedBody)"), + UIApplication.shared.canOpenURL(url) { + UIApplication.shared.open(url) } else { let text = String(format:L("email_error_body"), toRecipients.joined(separator: ";")) let alert = UIAlertController(title: L("email_error_title"), message: text, preferredStyle: .alert) -- 2.45.3 From 1d4c7fc6007c36875ba9422dccd2496e7ee904cd Mon Sep 17 00:00:00 2001 From: Valery Lozko Date: Tue, 9 Apr 2024 08:20:57 -0400 Subject: [PATCH 2/5] [ios] Add default email client support to about menu Signed-off-by: Valery Lozko --- .../AboutController/AboutController.swift | 32 +++++++++++++++---- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/iphone/Maps/UI/Help/AboutController/AboutController.swift b/iphone/Maps/UI/Help/AboutController/AboutController.swift index 8448c0a904..016d1dcaab 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 openDefaultApp(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,14 +505,18 @@ 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. - let encodedSubject = subject.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) ?? "" - let encodedBody = body.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) ?? "" - let correctEncodedBody = encodedBody.replacingOccurrences(of: "%0A", with: "%0D%0A") - if let url = URL(string: "mailto:\(toRecipients)?subject=\(encodedSubject)&body=\(correctEncodedBody)"), - UIApplication.shared.canOpenURL(url) { - UIApplication.shared.open(url) + // From iOS 14, it is possible to change the default mail app, and mailto should open a default mail app. + if openDefaultApp(subject: subject, body: body, recipients: toRecipients){ + return + } else 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) } else { let text = String(format:L("email_error_body"), toRecipients.joined(separator: ";")) let alert = UIAlertController(title: L("email_error_title"), message: text, preferredStyle: .alert) -- 2.45.3 From f8ca5db9d7533ac777f7f0e46269b5eeabcf10cd Mon Sep 17 00:00:00 2001 From: Valery Lozko Date: Sat, 20 Apr 2024 07:22:27 -0400 Subject: [PATCH 3/5] [ios] Add default email client support to about menu Signed-off-by: Valery Lozko --- .../UI/Help/AboutController/AboutController.swift | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/iphone/Maps/UI/Help/AboutController/AboutController.swift b/iphone/Maps/UI/Help/AboutController/AboutController.swift index 016d1dcaab..b105b481a1 100644 --- a/iphone/Maps/UI/Help/AboutController/AboutController.swift +++ b/iphone/Maps/UI/Help/AboutController/AboutController.swift @@ -509,14 +509,6 @@ private extension AboutController { // From iOS 14, it is possible to change the default mail app, and mailto should open a default mail app. if openDefaultApp(subject: subject, body: body, recipients: toRecipients){ return - } else 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) } else { let text = String(format:L("email_error_body"), toRecipients.joined(separator: ";")) let alert = UIAlertController(title: L("email_error_title"), message: text, preferredStyle: .alert) @@ -527,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) { -- 2.45.3 From 695465f398bcfcafe8aa0c202e1e12ed31f55cf4 Mon Sep 17 00:00:00 2001 From: Valery Lozko Date: Sat, 20 Apr 2024 08:16:00 -0400 Subject: [PATCH 4/5] [ios] Add default email client support to about menu Signed-off-by: Valery Lozko --- iphone/Maps/UI/Help/AboutController/AboutController.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iphone/Maps/UI/Help/AboutController/AboutController.swift b/iphone/Maps/UI/Help/AboutController/AboutController.swift index b105b481a1..db078eee9a 100644 --- a/iphone/Maps/UI/Help/AboutController/AboutController.swift +++ b/iphone/Maps/UI/Help/AboutController/AboutController.swift @@ -482,7 +482,7 @@ private extension AboutController { return false } - func openDefaultApp(subject: String, body: String, recipients: [String]) -> Bool { + func openDefaultMailApp(subject: String, body: String, recipients: [String]) -> Bool { var components = URLComponents(string: "mailto:\(recipients.joined(separator: ";"))") components?.queryItems = [ URLQueryItem(name: "subject", value: subject), @@ -507,7 +507,7 @@ private extension AboutController { } // From iOS 14, it is possible to change the default mail app, and mailto should open a default mail app. - if openDefaultApp(subject: subject, body: body, recipients: toRecipients){ + if openDefaultMailApp(subject: subject, body: body, recipients: toRecipients){ return } else { let text = String(format:L("email_error_body"), toRecipients.joined(separator: ";")) -- 2.45.3 From e63c0c22bb238ea17dd014163cbb9eef81267c5a Mon Sep 17 00:00:00 2001 From: v-lozko <156805389+v-lozko@users.noreply.github.com> Date: Wed, 24 Apr 2024 18:44:21 -0400 Subject: [PATCH 5/5] Update iphone/Maps/UI/Help/AboutController/AboutController.swift Co-authored-by: Alexander Borsuk <170263+biodranik@users.noreply.github.com> Signed-off-by: v-lozko <156805389+v-lozko@users.noreply.github.com> --- iphone/Maps/UI/Help/AboutController/AboutController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iphone/Maps/UI/Help/AboutController/AboutController.swift b/iphone/Maps/UI/Help/AboutController/AboutController.swift index db078eee9a..db1ca8263f 100644 --- a/iphone/Maps/UI/Help/AboutController/AboutController.swift +++ b/iphone/Maps/UI/Help/AboutController/AboutController.swift @@ -507,7 +507,7 @@ private extension AboutController { } // From iOS 14, it is possible to change the default mail app, and mailto should open a default mail app. - if openDefaultMailApp(subject: subject, body: body, recipients: toRecipients){ + if openDefaultMailApp(subject: subject, body: body, recipients: toRecipients) { return } else { let text = String(format:L("email_error_body"), toRecipients.joined(separator: ";")) -- 2.45.3