本文主要是介绍Swift-WKWebView,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
WKWebView 的navigationDelegate方法含义
// 页面开始加载时调用func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {}// 当内容开始返回时调用func webView(_ webView: WKWebView, didCommit navigation: WKNavigation!) {}// 页面加载完成之后调用func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {}// 页面加载失败时调用func webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error) {}// 接收到服务器跳转请求之后调用func webView(_ webView: WKWebView, didReceiveServerRedirectForProvisionalNavigation navigation: WKNavigation!) {}// 在收到响应后,决定是否跳转 -> 默认允许func webView(_ webView: WKWebView, decidePolicyFor navigationResponse: WKNavigationResponse, decisionHandler: @escaping (WKNavigationResponsePolicy) -> Void) {//允许跳转decisionHandler(.allow)//不允许跳转
// decisionHandler(.cancel)}// 在发送请求之前,决定是否跳转 -> 默认允许func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, preferences: WKWebpagePreferences, decisionHandler: @escaping (WKNavigationActionPolicy, WKWebpagePreferences) -> Void) {decisionHandler(.allow, preferences)}
这篇关于Swift-WKWebView的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!