我看到Apple的UIWebViewDelegate中未记录此行为:
如果我将NO返回给委托函数
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
立即使用错误101调用此函数(无法加载此URL。)。
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
由于我明确取消了请求,调用didFailLoadWithError是否正常?
答案 0 :(得分:2)
更新:如果手动取消连接,UIWebView将不会调用didFailLoadWithError。
我已通过测试验证了这一点。 didFailLoadWithError的原因是与UIWebView完全无关的其他东西。
答案 1 :(得分:0)
你应该总是返回no
shouldStartLoadWithRequest,如果网页视图应该开始加载内容,则返回YES
;否则,否
如果你的连接有错误101(net :: ERR_CONNECTION_RESET):未知错误,那么你可能会遇到这些:
You are trying to connect to the internet but the pages won’t load.
You are trying to refresh/reload the page so many times but to no avail.
You can see a lot of weird stuff all over the page. (links and images are unaligned.)
When the page doesn’t load, you can see the phrase “Error 101 (net::ERR_CONNECTION_RESET): Unknown error”.
您应始终将请求处理到您的委托并返回NO然后在收到的来自NSURLConnection的响应调用中取消连接,如果一切正常(检查响应)再次在webview中加载urlrequest。再次加载urlrequest时,请确保在上面的调用中返回YES。 或者你可以使用同步或异步方法来处理它。