Hey. This is probably obvious...But:
How should i call denied() function when decitionHandler is "(.cancel)" ?
Function to check if site is permitted:
func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
let url = navigationAction.request.url
if let host = url?.host {
for website in websites {
if host.contains(website){
decisionHandler(.allow)
return
}
}
decisionHandler(.cancel)
}
}
Function to call alert:
func denied() {
let ad = UIAlertController(title: "Permission denied", message: "Your are not allowed to CNBC", preferredStyle: .alert)
ad.addAction(UIAlertAction(title: "Close", style: .default, handler: nil))
present(ad, animated: true)
}
I tried to call it right after decisionHandler(.cancel), but alert is trigged for "first loaded" website as well.