From ea77504f3aad8e8787e776f27ea78483bde89a6c Mon Sep 17 00:00:00 2001 From: Stuart Breckenridge Date: Sat, 9 Jan 2021 05:56:13 +0800 Subject: [PATCH] percent encodes email addresses --- Multiplatform/iOS/Article/WebViewController.swift | 8 +++----- iOS/Article/WebViewController.swift | 8 +++----- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/Multiplatform/iOS/Article/WebViewController.swift b/Multiplatform/iOS/Article/WebViewController.swift index 8a552f39a..cd5ecf160 100644 --- a/Multiplatform/iOS/Article/WebViewController.swift +++ b/Multiplatform/iOS/Article/WebViewController.swift @@ -315,14 +315,12 @@ extension WebViewController: WKNavigationDelegate { } else if components?.scheme == "mailto" { decisionHandler(.cancel) - guard let _ = url.emailAddress else { + guard let emailAddress = URL(string: (url.emailAddress?.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed))!) else { return } - if UIApplication.shared.canOpenURL(url) { - UIApplication.shared.open(url, options: [.universalLinksOnly : false]) { (success) in - print(success) - } + if UIApplication.shared.canOpenURL(emailAddress) { + UIApplication.shared.open(emailAddress, options: [.universalLinksOnly : false], completionHandler: nil) } else { let alert = UIAlertController(title: NSLocalizedString("Error", comment: "Error"), message: NSLocalizedString("This device cannot send emails.", comment: "This device cannot send emails."), preferredStyle: .alert) alert.addAction(.init(title: NSLocalizedString("Dismiss", comment: "Dismiss"), style: .cancel, handler: nil)) diff --git a/iOS/Article/WebViewController.swift b/iOS/Article/WebViewController.swift index 35b6d28c3..fbe56fff9 100644 --- a/iOS/Article/WebViewController.swift +++ b/iOS/Article/WebViewController.swift @@ -356,14 +356,12 @@ extension WebViewController: WKNavigationDelegate { } else if components?.scheme == "mailto" { decisionHandler(.cancel) - guard let _ = url.emailAddress else { + guard let emailAddress = URL(string: (url.emailAddress?.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed))!) else { return } - if UIApplication.shared.canOpenURL(url) { - UIApplication.shared.open(url, options: [.universalLinksOnly : false]) { (success) in - print(success) - } + if UIApplication.shared.canOpenURL(emailAddress) { + UIApplication.shared.open(emailAddress, options: [.universalLinksOnly : false], completionHandler: nil) } else { let alert = UIAlertController(title: NSLocalizedString("Error", comment: "Error"), message: NSLocalizedString("This device cannot send emails.", comment: "This device cannot send emails."), preferredStyle: .alert) alert.addAction(.init(title: NSLocalizedString("Dismiss", comment: "Dismiss"), style: .cancel, handler: nil))