在iOS的wkwebview中捕获重定向URL [英] Capture redirect url in wkwebview in ios

查看:3535
本文介绍了在iOS的wkwebview中捕获重定向URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用WKWebView时如何捕获重定向URL,例如在提交用户名和密码或其他数据时网页重定向到另一个页面.我需要捕获重定向的URL. WKNavigationDelegate中是否有任何方法可以覆盖?

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 to capture the redirected url. Is there any method in WKNavigationDelegate to override?

推荐答案

使用此WKNavigationDelegate方法

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)
    }

希望这会有所帮助

这篇关于在iOS的wkwebview中捕获重定向URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆