[英]What's the difference between `WKNavigationDelegate` `didFail` and `didFailProvisionalNavigation`
iOS WKWebView's WKNavigationDelegate
has two methods to handle a failed navigation: iOS WKWebView 的
WKNavigationDelegate
有两种方法来处理失败的导航:
webView(_:didFail:withError:)
: "Tells the delegate that an error occurred during navigation." webView(_:didFail:withError:)
:“告诉委托人在导航过程中发生了错误。”
webView(_:didFailProvisionalNavigation:withError:)
: "Tells the delegate that an error occurred during the early navigation process." webView(_:didFailProvisionalNavigation:withError:)
:“告诉委托人在早期导航过程中发生了错误。”
The docs only tell us that the one type occurs earlier in the navigation process than the other.文档只告诉我们,一种类型在导航过程中比另一种更早出现。 The error arguments are generic, so no help there.
错误 arguments 是通用的,所以没有帮助。 Brave and Firefox iOS only handle
didFailProvisionalNavigation
as far as I can tell from reading their source. Brave 和 Firefox iOS 仅处理
didFailProvisionalNavigation
,据我阅读其源代码可知。
My questions are:我的问题是:
didFail
seeing that browsers don't seem to handle that?didFail
看到浏览器似乎无法处理? This method handles errors that happen before the resource of the url can even be reached.此方法处理甚至可以到达 url 的资源之前发生的错误。 These errors are mostly related to connectivity, the formatting of the url, or if using urls which are not supported.
这些错误主要与连接性、url 的格式或使用不受支持的 url 有关。
The error codes delivered here are found in https://developer.apple.com/documentation/c.network/c.networkerrors此处提供的错误代码位于https://developer.apple.com/documentation/c.network/c.networkerrors
Typical examples are典型的例子是
kCFURLErrorTimedOut = -1001 // timed out
kCFURLErrorUnsupportedURL = -1002 // unsupported URL
kCFURLErrorCannotFindHost = -1003 // host can not be found
kCFURLErrorFileDoesNotExist = -1100 // file does not exist on the server
Here errors are reported that happen while loading the resource.这里报告加载资源时发生的错误。 These are usually errors caused by the content of the page, like invalid code in the page itself that the parser can't handle.
这些通常是由页面内容引起的错误,例如页面本身中解析器无法处理的无效代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.