From 0d0b6b8fa618f280719a2c550db327958df8f188 Mon Sep 17 00:00:00 2001 From: Kiel Gillard Date: Thu, 16 Jan 2020 09:56:51 +1100 Subject: [PATCH] Gives iOS a chance to open universal links. #1625 --- iOS/Article/WebViewController.swift | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/iOS/Article/WebViewController.swift b/iOS/Article/WebViewController.swift index 1597bbd5a..47cca7e1f 100644 --- a/iOS/Article/WebViewController.swift +++ b/iOS/Article/WebViewController.swift @@ -354,9 +354,17 @@ extension WebViewController: WKNavigationDelegate { let components = URLComponents(url: url, resolvingAgainstBaseURL: false) if components?.scheme == "http" || components?.scheme == "https" { - let vc = SFSafariViewController(url: url) - present(vc, animated: true) decisionHandler(.cancel) + + // If the resource cannot be opened with an installed app, present the web view. + UIApplication.shared.open(url, options: [.universalLinksOnly: true]) { didOpen in + assert(Thread.isMainThread) + guard didOpen == false else { + return + } + let vc = SFSafariViewController(url: url) + self.present(vc, animated: true) + } } else { decisionHandler(.allow) }