iOS Development Network Programming--use nsurlconnection to achieve large file breakpoint continuation download

Source: Internet
Author: User

Network programming for iOS development--using nsurlconnection to achieve large file breakpoint continuation download is in the previous iOS Development network programming-using Nsurlconnection to achieve large file download based on

The settings for the continuation of the breakpoint. Network programming on iOS development-using Nsurlconnection to implement large file download details here, of course, will not be exhausted.

the principle of the continuation of the breakpoint :

Each time you request to download data from the server, tell the server to start the download from a location that is not yet downloaded from the entire stream of downloaded files, and then the server returns the data stream from that location.

Image:

    

The breakpoint continues to pass the key code:

    

API interface for doing code exercises :

MP4 Little Video: Http://120.25.226.186:32812/resources/videos/minion_01.mp4

Code Implementation (the following source is in the iOS development of the network programming-using Nsurlconnection to achieve large file download based on the further implementation of disconnection):

1, to achieve the download and stop the download, so you need to add two buttons, and then drag line connection what, you understand.

    

2. Key complete code:

      

For more information on using Nsurlconnection to implement a large file breakpoint download:

In my iOS development of the network programming-small file download of the essay blog post mentioned in the Response header object properties

    Instead of downloading the length of the entire file, response.expectedcontentlength Returns the length of the file that will be downloaded

As a practical example: when I download the length of the 1/3 and then cancel the download, and then click to start the download again, this time Response.expectedcontentlength will return the remaining 2/3 of the length.

So use response.expectedcontentlength to be careful not to use wrong because you don't know the nature of it.

The above source code:

    

Reprint please specify the Source: iOS Development Network Programming-use Nsurlconnection to achieve large file breakpoints to continue downloading, respect for the fruits of labor.

iOS Development Network Programming--use nsurlconnection to achieve large file breakpoint continuation download

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.