Skip to content

Instantly share code, notes, and snippets.

@cristinaITdeveloper
Created June 25, 2017 16:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cristinaITdeveloper/cd7dda6c7e0c0d0427c51a0da4b217aa to your computer and use it in GitHub Desktop.
Save cristinaITdeveloper/cd7dda6c7e0c0d0427c51a0da4b217aa to your computer and use it in GitHub Desktop.
Swift - Open link in safari from web view - iOS (use this method in viewcontroller that implement the UIWebViewDelegate protocol
func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebViewNavigationType) -> Bool {
switch navigationType {
case .linkClicked:
// Open links in Safari
guard let url = request.url else { return true }
if #available(iOS 10.0, *) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
} else {
// openURL(_:) is deprecated in iOS 10+.
UIApplication.shared.openURL(url)
}
return false
default:
// Handle other navigation types...
return true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment