From 608da70e8e9b5942bfe3ab49569e7c4e1cb24a6f Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Tue, 1 Oct 2019 11:09:46 -0500 Subject: [PATCH] Launch Safari when web preview is tapped. Issue #1090 --- iOS/Article/ArticleViewController.swift | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/iOS/Article/ArticleViewController.swift b/iOS/Article/ArticleViewController.swift index 374657506..3d7ae5b8f 100644 --- a/iOS/Article/ArticleViewController.swift +++ b/iOS/Article/ArticleViewController.swift @@ -101,6 +101,7 @@ class ArticleViewController: UIViewController { self.webView = webView self.webViewContainer.addChildAndPin(webView) webView.navigationDelegate = self + webView.uiDelegate = self // Even though page.html should be loaded into this webview, we have to do it again // to work around this bug: http://www.openradar.me/22855188 @@ -325,6 +326,17 @@ extension ArticleViewController: WKNavigationDelegate { } +// MARK: WKUIDelegate + +extension ArticleViewController: WKUIDelegate { + func webView(_ webView: WKWebView, contextMenuForElement elementInfo: WKContextMenuElementInfo, willCommitWithAnimator animator: UIContextMenuInteractionCommitAnimating) { + // We need to have at least an unimplemented WKUIDelegate assigned to the WKWebView. This makes the + // link preview launch Safari when the link preview is tapped. In theory, you shoud be able to get + // the link from the elementInfo above and transition to SFSafariViewController instead of launching + // Safari. As the time of this writing, the link in elementInfo is always nil. ¯\_(ツ)_/¯ + } +} + // MARK: Private private extension ArticleViewController {