diff --git a/Shared/Extensions/URL-Extensions.swift b/Shared/Extensions/URL-Extensions.swift index be121c334..1cac0dc6a 100644 --- a/Shared/Extensions/URL-Extensions.swift +++ b/Shared/Extensions/URL-Extensions.swift @@ -14,4 +14,9 @@ extension URL { var emailAddress: String? { scheme == "mailto" ? URLComponents(url: self, resolvingAgainstBaseURL: false)?.path : nil } + + /// Extracts telephone number from a `URL` with a `tel` scheme, otherwise `nil`. + var telNumber: String? { + scheme == "tel" ? URLComponents(url: self, resolvingAgainstBaseURL: false)?.path : nil + } } diff --git a/iOS/Article/WebViewController.swift b/iOS/Article/WebViewController.swift index 132dc48d7..c25d4b29b 100644 --- a/iOS/Article/WebViewController.swift +++ b/iOS/Article/WebViewController.swift @@ -314,7 +314,7 @@ extension WebViewController: WKNavigationDelegate { } else if components?.scheme == "mailto" { decisionHandler(.cancel) - guard let emailAddress = components?.url?.emailAddress else { + guard let emailAddress = url.emailAddress else { return } @@ -328,6 +328,13 @@ extension WebViewController: WKNavigationDelegate { alert.addAction(.init(title: "Dismiss", style: .cancel, handler: nil)) self.present(alert, animated: true, completion: nil) } + } else if components?.scheme == "tel" { + decisionHandler(.cancel) + + if UIApplication.shared.canOpenURL(url) { + UIApplication.shared.open(url, options: [.universalLinksOnly : false], completionHandler: nil) + } + } else { decisionHandler(.allow) }