Nsurlsessiondownloadtask for large file downloads

Source: Internet
Author: User
Tags tmp file

(1) using nsurlsession and nsurlsessiondownload can be very convenient for file download operation

/*     第一个参数:要下载文件的url路径     第二个参数:当接收完服务器返回的数据之后调用该block     location:下载的文件的保存地址(默认是存储在沙盒中tmp文件夹下面,随时会被删除)     response:服务器响应信息,响应头     error:该请求的错误信息     */    //说明:downloadTaskWithURL方法已经实现了在下载文件数据的过程中边下载文件数据,边写入到沙盒文件的操作    NSURLSessionDownloadTask *downloadTask = [session downloadTaskWithURL:url completionHandler:^(NSURL * __nullable location, NSURLResponse * __nullable response, NSError * __nullable error)

(2) Downloadtaskwithurl internal default has implemented the change download side write operation, so no developers worry about memory problems

(3) file download by default in the TMP file directory, developers need to manually cut to the appropriate sandbox directory

(4) Cons: No way to monitor download progress

Nsurlsessiondownloadtask for large file downloads

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.