码迷,mamicode.com
首页 > 移动开发 > 详细

iOS UIWebView 捕获403 、404错误

时间:2014-09-12 14:43:13      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:http   io   os   ar   for   art   sp   cti   on   

#pragma mark -
#pragma mark - UIWebView Delegate Methods
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
  static BOOL isRequestWeb = YES;

  if (isRequestWeb) {
    NSHTTPURLResponse *response = nil;

    NSData *data = [NSURLConnection sendSynchronousRequest:request                   returningResponse:&response error:nil];
  

    if (response.statusCode == 404) {
    // code for 404
    return NO;
    } else if (response.statusCode == 403) {
    // code for 403
    return NO;
    }

    [webView loadData:data MIMEType:@"text/html" textEncodingName:nil baseURL:[request URL]];
  
    isRequestWeb = NO;
    return NO;
  }

  return YES;
}

iOS UIWebView 捕获403 、404错误

标签:http   io   os   ar   for   art   sp   cti   on   

原文地址:http://www.cnblogs.com/zhujin/p/3968209.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!