确认网络环境
来源:互联网 发布:刘建明 知乎 编辑:程序博客网 时间:2024/05/29 16:23
网络编程 开发web等网络应用程序的时候,需要确认网络环境,连接情况等信息。如果没有处理它们,是不会通过apple的审查的。 系统自带的网络检查是原生的,AFNetworking也为我们添加了相关检测机制,所以这个直接在介绍AFNetworking的时候详解吧。
使用NSURLConnection
下载数据
1. 创建对象NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://www.baidu.com"]];[NSURLConnection connectionWithRequest:request delegate:self];2. NSURLConnection delegate 委托方法- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {}- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { }- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { }- (void)connectionDidFinishLoading:(NSURLConnection *)connection { }3. 实现委托方法- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { self.receiveData.length = 0;//先清空数据}- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { [self.receiveData appendData:data];}- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { //错误处理}- (void)connectionDidFinishLoading:(NSURLConnection *)connection { [UIApplication sharedApplication].networkActivityIndicatorVisible = NO; NSString *returnString = [[NSString alloc]initWithData:self.receiveData encoding:NSUTF8StringEncoding]; firstTimeDownloaded = YES;}
0 0
- 确认网络环境
- 确认网络环境 3G/WIFI
- 确认网络环境3G/WIFI
- iPhone开发之确认网络环境
- 确认网络环境 3G/WIFI
- iPhone开发之确认网络环境
- 网络编程总结(解析数据,下载文件,确认网络环境)
- 确认网络环境3G/WIFI Reachability的使用
- ios利用Reachability确认网络环境3G/WIFI
- IOS之确认网络环境(3G/WIFI)
- ios利用Reachability确认网络环境3G/WIFI
- ios利用Reachability确认网络环境3G/WIFI
- ios利用Reachability确认网络环境3G/WIFI
- ios利用Reachability确认网络环境3G/WIFI
- ios利用Reachability确认网络环境3G/WIFI(转)
- iPhone开发技巧之网络篇(4)--- 确认网络环境 3G/WIFI
- Reachability 网络编程总结(解析数据,下载文件,确认网络环境)
- iPhone开发技巧之网络篇--- 确认网络环境 3G/WIFI
- 九度oj 1193
- JSP中输入框的设置问题
- 通俗易懂讲解happens-before原则
- HTTP/TCP/UDP协议详解
- iOS 多线程介绍
- 确认网络环境
- ORB特征点检测
- 多线程--何时用到多线程
- C# Chart 控件快速使用
- Redis BRPOP key [key ...] timeout
- 812 水题~~【进制转化】
- 两种删除旧内核的方法
- OpenLDAP学习笔记
- 自适应页面布局使得应用适应不同屏幕的尺寸变得更加容易