I am developing a web view application with Swift programming language.
I made a control on the URL because if it's a URL of Youtube,Facebook or something else external to the primary website, I want to open the URL in Safari. Until here everything ok.
The problem is when I click on a link (is a simple link that should open in Safari) the application crash with this error EXC_BAD_INSTRUCTION(code=EXC_I386_INVOP,subcode=0x0) on the "*" line.
func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebViewNavigationType) -> Bool {
*let stringaURL = try! String(contentsOf: request.url!)*
if navigationType == UIWebViewNavigationType.linkClicked{
if((stringaURL.range(of:"www.collegiodeirettori.net/palio/")) != nil ){
print(stringaURL)
}
else{
UIApplication.shared.openURL(request.url!)
return false;
}
}
return true;
}
Some advice to solve the problem? Thanks