Search code examples
xcodeswift3uiwebviewuiwebviewdelegate

xcode swift UIWebview disable links to open that start with https://m


Hey guys so intially im loading a https://www.etcccc link but its a video and it has an overlay image that if clicked it will navigate to a https://m.etccccc,,, I just need to restrict urls that start with a "m" instead of "www" to return a false in the shouldstartloadrequest but im having issues. All help is appreciated


Solution

  • webview delegate shouldStartLoadWith request is best place to restrict the url.try this

    func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebViewNavigationType) -> Bool {
    
            if request.url?.host?.hasPrefix("m") == true{
             return false
            }
            else{
             return true
            }
      }