iPhone开发 从UIWebView中获取Status Code 实例教程是本文要介绍的内容,本文是基于代码实现,内容不多,我们来看实现代码。
从 UIWebView 中获取 Status Code ,比如 404 之类的报错信息,可以使用苹果官网提供的代码
- - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
- // check for HTTP status code for proxy authentication failures
- // anything in the 200 to 299 range is considered successful,
- // also make sure the MIMEType is correct:
- //
- NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
- if ((([httpResponse statusCode]/100) == 2)) {
- // self.earthquakeData = [NSMutableData data];
- [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
- } else {
- NSDictionary *userInfo = [NSDictionary dictionaryWithObject:
- NSLocalizedString(@"HTTP Error",
- @"Error message displayed when receving a connection error.")
- forKey:NSLocalizedDescriptionKey];
- NSError *error = [NSError errorWithDomain:@"HTTP" code:[httpResponse statusCode] userInfo:userInfo];
- [self handleError:error];
- }
- }
小结:iPhone开发 从UIWebView中获取Status Code 实例教程的内容介绍完了,希望本文对你有所帮助。
本文来自:http://www.cocoachina.com/iphonedev/sdk/2010/1202/2429.html