Network Programming for iOS development-using NSURLConnection for large file downloads and iosnsurlconnection

Source: Internet
Author: User

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.

Related Article

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.