Launch Safari when web preview is tapped. Issue #1090

This commit is contained in:
Maurice Parker 2019-10-01 11:09:46 -05:00
parent f4d58bd7a7
commit 608da70e8e
1 changed files with 12 additions and 0 deletions

View File

@ -101,6 +101,7 @@ class ArticleViewController: UIViewController {
self.webView = webView self.webView = webView
self.webViewContainer.addChildAndPin(webView) self.webViewContainer.addChildAndPin(webView)
webView.navigationDelegate = self webView.navigationDelegate = self
webView.uiDelegate = self
// Even though page.html should be loaded into this webview, we have to do it again // 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 // 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 // MARK: Private
private extension ArticleViewController { private extension ArticleViewController {