关于小文件下载

其实我们经常用的[NSData dataWithContentsOfURL] 就是一种文件下载方式,猜测这里面应该是发送了Get请求。

下载代码应该放到子线程执行

NSURLConnection方式下载

NSURL* url = [NSURL URLWithString:@"https://picjumbo.imgix.net/HNCK8461.jpg?q=40&w=1650&sharp=30"];
[NSURLConnection sendAsynchronousRequest:[NSURLRequest requestWithURL:url] queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {

self.imageView.image = [UIImage imageWithData:data];
    }];

就是发送一个异步的Get请求,回调的data就是我们下载到的图片。
原文地址:https://www.cnblogs.com/ZGSmile/p/5828764.html