在实际开发过程中,经常会遇到文件的下载操作,接下来就介绍一下文件下载的操作
方法:
a> 使用 [NSData dataWithContentsOfURL
dispatch_async(dispatch_get_global_queue(0, 0), ^{
NSURL *url = [NSURL URLWithString:@"下载地址”];
NSData *data = [NSData dataWithContentsOfURL:url];
NSLog(@"%d", data.length);
});
NSURL *url = [NSURL URLWithString:@"下载地址"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
NSLog(@"%d", data.length);
}];