percent encodes email addresses

This commit is contained in:
Stuart Breckenridge 2021-01-09 05:56:13 +08:00
parent c59e3e4ddf
commit ea77504f3a
No known key found for this signature in database
GPG Key ID: ED2F112EEA9EF8A5
2 changed files with 6 additions and 10 deletions

View File

@ -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))

View File

@ -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))