I am opening links in Webviewcontroller. I have created a button on webview controller to open that link in Safari Browser. Problem I am facing is when I open url before it get load completely in web view controller, it open in Safari browser successfully. But when URL loaded completely in webview controller, it doesn't open Safari Broswer.
My Code is:
let alertController = UIAlertController(title: nil, message: nil, preferredStyle: UIAlertControllerStyle.actionSheet)
alertController.addAction(UIAlertAction(title: NSLocalizedString("Open in Safari", comment: ""), style: .default, handler: { (UIAlertAction) -> Void in
self.openInSafari()
}))
if (UIDevice.current.userInterfaceIdiom == .phone){
alertController.addAction(UIAlertAction(title: NSLocalizedString("Cancel",comment: ""), style: .cancel, handler:nil))
}
And Function to open Safari Browser:
func openInSafari(){
if #available(iOS 10.0, *) {
UIApplication.shared.open(URL(string: self.currentUrl)!, options: [:],completionHandler: nil)
} else {
UIApplication.shared.openURL(URL(string: self.currentUrl)!)
}
}
Screenshots: