1 | var getImageTask:NSURLSessionDownloadTask = |
创建一个图片下载任务,NSURL是下载任务网址,completionHandler指定任务完成后的回调代码块,responce是一个闭包,任务完成后在主线程更新imageview
过程:
在 downloadtask 中
- download task convenience methods. When a download successfully
- completes, the NSURL will point to a file that must be read or
- copied during the invocation of the completion routine. The file
- will be removed automatically.
下载任务完成后,调用协议的
1 | func URLSession(session: NSURLSession, downloadTask: NSURLSessionDownloadTask, didFinishDownloadingToURL location: NSURL){} |
方法
dataTaskWithRequest过程:
1.创建一个NSMutableURLRequest类
2.用NSMutableURLRequest作为参数创建一个任务,类为dataTaskWithURL