Posts

Post marked as solved
2 Replies
340 Views
Hi, I have a WebView based app, I want any external links within the default website in the WebView to open in a new Safari browser tab rather than within the Website I am displaying through the app. In the ViewController, I have: import UIKit import WebKit import CoreLocation class ViewController: UIViewController, WKNavigationDelegate { var webView: WKWebView! override func loadView() { webView = WKWebView() webView.navigationDelegate = self view = webView let url = URL(string: "https://domain.com")! webView.load(URLRequest(url: url)) webView.allowsBackForwardNavigationGestures = true webView.navigationDelegate = self } func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) { if let url = navigationAction.request.url { if url.host != "https://domain.com" { UIApplication.shared.open(url) decisionHandler(.cancel) return } } decisionHandler(.allow) }} But, rather than it opening a new Safari browser when you tap onto an external link, when the app launches, the website I have contained within the app opens in Safari. Is there anything I can do to try and resolve this issue? Any help is appreciated.
Posted
by dafo.
Last updated
.