Jiang ===afnetworking Download video files

Source: Internet
Author: User

Gets the code for the documents address in the sandbox.

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);NSString *documentsDirectory = [paths objectAtIndex:0];
    • 1
    • 2
    • 1
    • 2

Assuming the network URL for the video file is Http://www.abc.com/test.mp4, the file that is downloaded to the iOS sandbox is named Test.mp4.

The following code can be used to download and store video files, note that when generating the network URL using the Nsurl class method urlwithstring, so that you can request the network URL, using Fileurlwithpath to access local files. This is a little bit of a pit I met and wasted a lot of time.

Afhttpsessionmanager *manager = [Afhttpsessionmanager manager];NSString *fullpath = [NSString stringwithformat:@"%@/%@", Documentsdirectory, @"Test.mp4"]; Nsurl *url = [nsurl urlwithstring:@"Http://www.abc.com/test.mp4"];  Nsurlrequest *request = [nsurlrequest requestwithurl:url]; Nsurlsessiondownloadtask *task =[manager downloadtaskwithrequest:request progress:nil destination:^NSURL * ( nsurl *targetpath, Nsurlresponse *response) { return [nsurl Fileurlwithpath:fullpath];} completionhandler:^ (Nsurlresponse *response, Nsurl * FilePath, nserror *error) {}]; [Task resume];             

Jiang ===afnetworking Download video files

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.