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

查看:126
本文介绍了在 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 let redirectedUrl = navigationAction.request.url {
                //do what you need with url
                //self.delegate?.openURL(url: redirectedUrl)
            }
            decisionHandler(.cancel)
            return
        }
        decisionHandler(.allow)
    }

希望对你有帮助

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

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