欢迎访问移动开发之家(rcyd.net),关注移动开发教程。移动开发之家  移动开发问答|  每日更新
页面位置 : > > > 内容正文

iPhone开发 从UIWebView中获取Status Code实例教程

来源: 开发者 投稿于  被查看 24359 次 评论:232

iPhone开发 从UIWebView中获取Status Code实例教程


iPhone开发 从UIWebView中获取Status Code 实例教程是本文要介绍的内容,本文是基于代码实现,内容不多,我们来看实现代码。

从 UIWebView 中获取 Status Code ,比如 404 之类的报错信息,可以使用苹果官网提供的代码

  1. - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {  
  2.     // check for HTTP status code for proxy authentication failures  
  3.     // anything in the 200 to 299 range is considered successful,  
  4.     // also make sure the MIMEType is correct:  
  5.     //  
  6.     NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;  
  7.     if ((([httpResponse statusCode]/100) == 2)) {  
  8.         // self.earthquakeData = [NSMutableData data];  
  9.         [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;  
  10.     } else {  
  11.         NSDictionary *userInfo = [NSDictionary dictionaryWithObject:  
  12.                                   NSLocalizedString(@"HTTP Error",  
  13.                                                     @"Error message displayed when receving a connection error.")  
  14.                                                              forKey:NSLocalizedDescriptionKey];  
  15.         NSError *error = [NSError errorWithDomain:@"HTTP" code:[httpResponse statusCode] userInfo:userInfo];  
  16.         [self handleError:error];  
  17.     }  

小结:iPhone开发 从UIWebView中获取Status Code 实例教程的内容介绍完了,希望本文对你有所帮助。

本文来自:http://www.cocoachina.com/iphonedev/sdk/2010/1202/2429.html

用户评论