Main ideas (implementing the download data fragment write cache)
1, using Nsurlconnectiondatadelegate and proxy method.
2. In the agent method that successfully gets the response, obtain the full path to the sandbox and create an empty file and file handle under the path.
3, in the proxy method to get data, first set the handle at the end of the sandbox full path file, and then write data through the handle.
4. In the agent method where the file is downloaded, close the handle and set the handle reference to the nil release handle and pointer.
Use the thought diagram of the handle (the red arrow indicates the handle, and the gray arrow indicates the path of the move):
Code keywords:
Class: Methods of Nsfilehandle
1, Filehandleforwritingatpath through the file path to get the file, and create a file handle
2. seektoendoffile file handle moved to end of file
3. WriteData writes data to file
4. CloseFile Close File handle
code example:
API interface for doing code exercises
MP4 Little Video: Http://120.25.226.186:32812/resources/videos/minion_03.mp4
about using Nsurlconnection to implement large file breakpoints download please see next: iOS Development Network Programming-using Nsurlconnection to achieve large file breakpoints to continue downloading.
Reproduced please specify the source: http://www.cnblogs.com/goodboy-heyang/p/5189817.html, respect for the fruits of labor.
iOS Development Network Programming-using Nsurlconnection for large file downloads