iOS-UIWebview设置超时、加载失败、重新加载等问题解决
来源:互联网 发布:怎么给手机网络加速 编辑:程序博客网 时间:2024/05/22 00:16
iOS开发 UIWebView加载失败 我想重新加载怎么做,使用reload不顶用
解决办法:重新使用
loadRequest:
设置超时
NSURL *url=[NSURL URLWithString:@"http://www.baidu.com"]; NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:2]; UIWebView* webView = [[UIWebView alloc]initWithFrame:self.view.bounds]; webView.delegate=self; [webView loadRequest:request]; [self.view addSubview:webView];}
超时额外提示或者其他自定义操作
- (void)viewDidLoad { [super viewDidLoad]; UIWebView *webview = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; [self.view addSubview:myWebview]; NSURL *url = [NSURL URLWithString:@"www.baidu.com"]; NSURLRequest *request =[NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:0.5]; [webview loadRequest:request]; if (theConnection) { [theConnection cancel]; NSLog(@"safe release connection"); } theConnection= [[NSURLConnection alloc]initWithRequest:request delegate:self startImmediately:YES];}-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{ if (theConnection) { NSLog(@"safe release connection"); } if ([response isKindOfClass:[NSHTTPURLResponse class]]){ NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*)response; if ((([httpResponse statusCode]/100) == 2)){ NSLog(@"connection ok"); } else{ NSError *error = [NSError errorWithDomain:@"HTTP" code:[httpResponse statusCode] userInfo:nil]; if ([error code] == 404){ NSLog(@"404"); } } }}-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{ if (theConnection) { NSLog(@"safe release connection"); } if (error.code == 22) //The operation couldn’t be completed. Invalid argument NSLog(@"22"); else if (error.code == -1001) //The request timed out. webview code -999的时候会收到-1001,这里可以做一些超时时候所需要做的事情,一些提示什么的 NSLog(@"-1001"); else if (error.code == -1005) //The network connection was lost. NSLog(@"-1005"); else if (error.code == -1009){ //The Internet connection appears to be offline NSLog(@"-1009"); }}
相关网络加载失败提示封装
HCWProgressHUD *hud = [HCWProgressHUD showHUDAddedTo:self.view animated:YES tapContentBlock:^(HCWProgressHUDMode mode) {} clickButtonBlock:^(HCWProgressHUDMode mode) {}];hud.buttonCorlor = [UIColor blueColor];// 没有网络dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ hud.mode = HCWProgressHUDModeNoInternet; // 没有数据 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ hud.mode = HCWProgressHUDModeNoData; // 隐藏 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [HCWProgressHUD hideHUDForView:self.view animated:YES]; }); });});
阅读全文
0 0
- iOS-UIWebview设置超时、加载失败、重新加载等问题解决
- iOS 加载UIWebView 网址
- iOS UIWebView 的加载
- iOS UIwebview的加载
- iOS中使用UIWebView无法加载URL的问题解决
- 隐藏TabBar后,UIWebView加载过程中和加载失败时,底部出现黑边的问题解决
- iOS-UIWebView加载html,文字大小颜色设置,图片自适应设置
- ios使用UIWebView加载使用说明或者协议等文本方法
- 网络请求加载控件的简单实现,能显示加载中、没网络、加载失败点击重新加载等状态
- spring bean重新加载问题解决
- IOS UIWebView加载网页实例
- UIWebView加载本地html ios
- iOS开发-UIWebView加载方式
- iOS UIWebView加载本地图片
- iOS UIWebView加载html代码
- iOS网页-加载网页(UIWebView)
- img 图片加载设置超时
- iOS中使用SDWebImage加载图片失败之后如何重新加载
- mysql 多主多从
- C#比较两个list集合,两集合同时存在或A集合存在B集合中无
- asp net core 跨平台初体验
- 代码格式
- 阿里云首推音乐变速短视频SDK,上线抖音 freestyle只需1步
- iOS-UIWebview设置超时、加载失败、重新加载等问题解决
- 工作日记2017.07.25
- python3.* No module named ‘MySQLdb'
- 再三强调直流电机无刷系列的特点和优势
- 4个你未必知道的内存小知识
- 给予jquery的进度条,三列数据
- 关于Java多文件上传
- Latex常用数学符号
- 没有绝对安全的系统:写在AES 256破解之后