How to detect and handle HTTP error codes in UIWebView?

前端 未结 9 677
无人及你
无人及你 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条回答
  •  执笔经年
    2021-02-02 12:30

    I used below code for my solution

    -(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
    NSLog(@"error  :%@",error);
    
    NSString *strError = [NSString stringWithFormat:@"%@",error];
    
    if ([strError rangeOfString:@"Code=-1005"].location == NSNotFound) {
        NSLog(@"string does not contain Code=-1005");
    } else 
        NSLog(@"string contains Code=-1005”);
    

    }

提交回复
热议问题