Capture redirect url in wkwebview in ios

后端 未结 5 1324
孤独总比滥情好
孤独总比滥情好 2020-12-09 02:09

How do I capture the redirection url in when using WKWebView like if a webpage redirects to another page on submitting the username and password or some other data. I need t

5条回答
  •  温柔的废话
    2020-12-09 02:49

    Use this WKNavigationDelegate method

    public func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Swift.Void) {
            if(navigationAction.navigationType == .other) {
                if navigationAction.request.url != nil {
                    //do what you need with url
                    //self.delegate?.openURL(url: navigationAction.request.url!)
                }
                decisionHandler(.cancel)
                return
            }
            decisionHandler(.allow)
        }
    

    Hope this helps

提交回复
热议问题