1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| -(void)HttpManagerDownload { NSURL *url=[NSURL URLWithString:@"http://localhost:8080//MJServer/resources/videos/minion_01.mp4"]; //2-请求 NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:url]; AFHTTPSessionManager *mgr=[AFHTTPSessionManager manager]; NSURLSessionDownloadTask *task= [mgr downloadTaskWithRequest:request progress:nil destination:^NSURL * _Nonnull(NSURL * _Nonnull targetPath, NSURLResponse * _Nonnull response) { NSURL *cacheURL= [[[NSFileManager defaultManager]URLsForDirectory:NSCachesDirectory inDomains:NSUserDomainMask]lastObject]; return [cacheURL URLByAppendingPathComponent:[response suggestedFilename]]; } completionHandler:^(NSURLResponse * _Nonnull response, NSURL * _Nullable filePath, NSError * _Nullable error) { NSLog(@"File downloaded to: %@", filePath); }]; [task resume]; }
|