开发者

Is didFailLoadWithError normally called after I return NO in the delegate function shouldStartLoadWithRequest?

开发者 https://www.devze.com 2023-03-28 04:47 出处:网络
I am seeing this behavior not documented in Apple\'s UIWebViewDelegate: If I return NO to the delegate function

I am seeing this behavior not documented in Apple's UIWebViewDelegate:

If I return NO to the delegate function

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {

This function is immediately called with the error 101 (This URL cannot be loaded.).

- (void)webView:(UIWe开发者_如何学运维bView *)webView didFailLoadWithError:(NSError *)error {

Since I explicitly cancelled the request, is it even normal for didFailLoadWithError to be invoked?


Update: UIWebView will NOT call didFailLoadWithError if you manually cancel the connection.

I've verified this with testing. The reason why didFailLoadWithError is for something else completely unrelated to UIWebView.


You should always return no shouldStartLoadWithRequest, return YES if the web view should begin loading content; otherwise, NO

If your connection has Error 101 (net::ERR_CONNECTION_RESET): Unknown error, then you are maybe experiencing these:

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”.

You should always handle the request in to your delegate and return NO Then in the received response call from NSURLConnection cancel the connection and if everything is fine (check response) load the urlrequest once more in the webview. Make sure to return YES in the above call when loading the urlrequest again. or you can handle it with use of the Synchronous or Asynchronous methods.

0

精彩评论

暂无评论...
验证码 换一张
取 消