0

I am trying to prevent users from being able to navigate to different pages on a website by using WKNavigationDelegate and implementing the function below:


func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
        if let urlStr = navigationAction.request.url?.absoluteString {
            if urlStr == "https://random.ca/#/profile" {
                decisionHandler(.cancel)
                return
            }
        }
        decisionHandler(.allow)
    }

This function seems to only be called when I first load the home page of the website and when I navigate to other pages inside of this site it is not triggered and so I cannot prevent the user from navigating to those pages.

Any advice would be greatly appreciated.

1 Answers1

0

I found something

Just before calling webView.load()

add this

webView.isUserInteractionEnabled = false

check this Disable links in WKWebView? for more details

Jintor
  • 607
  • 8
  • 32