Network Programming for iOS development-using NSURLConnection for resumable download of large files and iosnsurlconnection
Network Programming for iOS development-using NSURLConnection to implement resumable download of large files is based on network programming of the previous iOS development-using NSURLConnection to download large files
Resumable upload settings. Network Programming for iOS development-details about how to use NSURLConnection to download large files will certainly not be described here.
Principle of resumable Data Transfer:
Each time you request to download data from the server, you must tell the server to start downloading from a non-download location of the data stream of the entire downloaded file. Then, the server returns the data stream starting from that location.
Image:
Key code for resumable upload:
APIs used for code exercises:
MP4 video: http: // 120.25.226.186: 32812/resources/videos/minion_01.mp4
Code implementation (the source code below is network programming developed in iOS-using NSURLConnection for large file downloads to further achieve broken line resume):
1. Implement download and stop download, so you need to add two buttons, and then drag the lines to connect or something, you know.
2. Complete key code:
Supplement:
Network Programming in iOS development-attributes of the response header object mentioned in the essay post on small File Download
Response. expectedContentLength does not return the length of the downloaded object, but the length of the object to be downloaded.
For example, when I download the length of 1/3 and then cancel the download, and then click Start to download again, the response. expectedContentLength will return the remaining length of 2/3.
Therefore, when using response. expectedContentLength, be sure not to use it incorrectly because you do not know its nature.
In the above source code:
Reprinted, please indicate the source: Network Programming for iOS development-use NSURLConnection to implement resumable download of large files and respect the fruits of labor.