检测网络图片存不存在的方法
来源:互联网 发布:猫眼软件下载 编辑:程序博客网 时间:2024/06/05 15:54
先用
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
判断一下当前的链接。
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
if ((([httpResponse statusCode]/100) == 2)) {
// self.earthquakeData = [NSMutableData data];
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
[ webView loadRequest:[ NSURLRequest requestWithURL: myUrl ]];
webView.delegate = self;
} 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];
if ([error code] == 404) {
NSLog(@"网络图片不存在");
webView.hidden = YES; //隐藏webView或者用本地默认图片代替
}
}
}
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
判断一下当前的链接。
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
if ((([httpResponse statusCode]/100) == 2)) {
// self.earthquakeData = [NSMutableData data];
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
[ webView loadRequest:[ NSURLRequest requestWithURL: myUrl ]];
webView.delegate = self;
} 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];
if ([error code] == 404) {
NSLog(@"网络图片不存在");
webView.hidden = YES; //隐藏webView或者用本地默认图片代替
}
}
}
0 0
- 检测网络图片存不存在的方法
- img加载图片不存在的处理方法
- matlab中保存图片的方法
- 检测网络状态的方法
- 网络超时检测的方法
- 网络检测的简单方法
- 当网页图片不存在时的处理方法
- 当网页图片不存在时的处理方法
- 当网页图片不存在时的处理方法
- 当页面图片不存在时的处理方法
- 网络不存在或尚未启动的处理方法
- 网络连接状态检测的一个方法
- 检测网络连接是否正常的方法
- 网络超时检测的三种方法
- Android,检测网络状态的方法
- 加载网络图片的方法
- 使用存储过程实现oracle存图片的方法
- matlab循环中保存.jpg图片的方法
- Window 常用系统变量
- 编写程序,自定义一函数,用来判断一个整数是否为素数,主函数输入一个数,输出是否为素数
- Media SDKv1.0 正式版发布
- 生成缩略图
- NVIDIA正式宣布CUDA 6.0:支持统一寻址!
- 检测网络图片存不存在的方法
- window下使用wireshark远程抓包
- 电脑店PE+CDlinux+360系统急救盘+Ubuntu+fedora+backtrack(上)(by 星空武哥)
- ArcGIS for JavaScript 用例学习---CreateMap
- jQuery操作Table学习总结
- c语言删除重复字符
- web 开发中forward动作指令和include动作指令的区别
- 伪共享
- svn 配置详解,以及各种可能遇到的问题