Gets the code for the documents address in the sandbox.
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);NSString *documentsDirectory = [paths objectAtIndex:0];
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