File Download Method:
-
If the downloaded file is small, download the method:
- Directly with NSData's + (ID) Datawithcontentsofurl: (nsurl*) URL;
- Use Nsurlconnection to send an HTTP request to download
- If you are downloading pictures, you can also use the Sdwebimage framework (not described herein)
-
If the downloaded file is larger, download the method:
- Using the Nsconnectiondatadelegate proxy method
- Recommended use of nsurlsession or third-party frameworks (not described herein)
code example:
Give the API interface to do the code exercises first
Small Picture: http://img2.duitang.com/uploads/blog/201310/18/20131018213446smuw4.thumb.7000.jpeg
MP4 Little Video: Http://120.25.226.186:32812/resources/videos/minion_03.mp4
1. Here are two ways to download small files such as small images:
For the second type of asynchronous request through Nsurlconnection can also request a slightly larger file, such as MP4 small video files, but because the file is relatively large, it will appear wait a long time to get results, in fact, is
There is a blocking, because it is an asynchronous request, so it does not affect the main thread, if you are using a synchronous request, it will affect the main thread. You can try it, there is no source code.
2, and then introduce how to use the Nsurlconnectiondatadelegate proxy method to this MP4 small video slightly larger files
Also show the print results:
SOURCE Baidu Cloud Share Link: Http://pan.baidu.com/s/1jHycCIU Password: 9kum
iOS Development Network Programming--File Download (i)