How to detect and handle HTTP error codes in UIWebView?

前端 未结 9 678
无人及你
无人及你 2021-02-02 11:54

I want to inform user when HTTP error 404 etc is received. How can I detect that? I\'ve already tried to implement

- (void)webView:(UIWebView *)webView didFailL         


        
9条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-02 12:48

    You could capture the URLRequest here:

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

    and hand the request over to the 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.

    Not very elegant, but it might work.

提交回复
热议问题