Adds to the URL-Extensions file

This commit is contained in:
Stuart Breckenridge 2021-01-09 06:09:50 +08:00
parent ea77504f3a
commit f85c1234a5
No known key found for this signature in database
GPG Key ID: ED2F112EEA9EF8A5
3 changed files with 7 additions and 2 deletions

View File

@ -315,7 +315,7 @@ extension WebViewController: WKNavigationDelegate {
} else if components?.scheme == "mailto" {
decisionHandler(.cancel)
guard let emailAddress = URL(string: (url.emailAddress?.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed))!) else {
guard let emailAddress = url.percentEncodedEmailAddress else {
return
}

View File

@ -15,6 +15,11 @@ extension URL {
scheme == "mailto" ? URLComponents(url: self, resolvingAgainstBaseURL: false)?.path : nil
}
/// Percent encoded `mailto` URL for use with `canOpenUrl`. If the URL doesn't contain the `mailto` scheme, this is `nil`.
var percentEncodedEmailAddress: URL? {
scheme == "mailto" ? self.string.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)?.url : nil
}
/// URL pointing to current app version release notes.
static var releaseNotes: URL {
let appVersion = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String ?? ""

View File

@ -356,7 +356,7 @@ extension WebViewController: WKNavigationDelegate {
} else if components?.scheme == "mailto" {
decisionHandler(.cancel)
guard let emailAddress = URL(string: (url.emailAddress?.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed))!) else {
guard let emailAddress = url.percentEncodedEmailAddress else {
return
}