Network Programming for iOS development-using NSURLConnection for large file downloads and iosnsurlconnection
Main Idea (implement multipart Writing of downloaded data into the cache)
1. Use NSURLConnectionDataDelegate and the proxy method.
2. In the proxy method for successfully obtaining the response, obtain the full sandbox path and create an empty file and file handle under the path.
3. In the proxy method for getting data, first set the handle to the end of the full path file in the sandbox, and then write data through the handle.
4. In the proxy method after the file is downloaded, close the handle and set the handle reference to nil to release the handle and pointer.
Use the handle idea diagram (the red arrow indicates the handle, and the gray arrow indicates the moving path ):
Code keywords:
Class: NSFileHandle Method
1. fileHandleForWritingAtPath obtains the file through the file path and creates a file handle.
2. Move the seekToEndOfFile file handle to the end of the file
3. writeData writes Data to a file
4. close the file handle in closeFile
Sample Code:
APIs used for code exercises
MP4 video: http: // 120.25.226.186: 32812/resources/videos/minion_03.mp4
For more information about how to use NSURLConnection for resumable download of large files, see the next article: Network Programming for iOS development-using NSURLConnection for resumable download of large files.
For more information, see http://www.cnblogs.com/goodboy-heyang/p/5189817.html.