码迷,mamicode.com
首页 > 移动开发 > 详细

[iOS]NSURLConnection的一个小例子

时间:2015-01-29 10:25:23      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:

直接上代码了。。。


在iOS7之后可以使用NSURLSession,但是考虑到兼顾iOS6还是使用NSURLConnection。



@interface ViewController() <NSURLConnectionDataDelegate>
@property (nonatomic,strong) NSMutableData *receivedData;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    NSURLRequest *theRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.baidu.com"]
                                                cachePolicy:NSURLRequestUseProtocolCachePolicy
                                            timeoutInterval:10.0];

    NSURLConnection *theConncetion=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];

    if (theConncetion) {
        _receivedData = [NSMutableData data];
    }

}

-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
    [_receivedData appendData:data];
    NSLog(@"Downloading...");
}

-(void)connectionDidFinishLoading:(NSURLConnection *)connection {
    NSLog(@"Finished");
}

@end


[iOS]NSURLConnection的一个小例子

标签:

原文地址:http://blog.csdn.net/pleasecallmewhy/article/details/43267359

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!