//沙盒的路径
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
AFHTTPSessionManager * manager = [AFHTTPSessionManager manager];
//沙盒的全路径
NSString *fullPath = [NSString stringWithFormat:@"%@/%@", documentsDirectory, @"test11.mov"];
NSURL *url = [NSURL URLWithString:@"http://tb-video.bdstatic.com/tieba-smallvideo-transcode/20985849_722f981a5ce0fc6d2a5a4f40cb0327a5_3.mp4"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
//targetPath为目标路径
NSURLSessionDownloadTask *task =
[manager downloadTaskWithRequest:request
progress:nil destination:^NSURL *(NSURL *targetPath, NSURLResponse *response) {
//返回的是全路径
return [NSURL fileURLWithPath:fullPath];
}
completionHandler:^(NSURLResponse *response, NSURL *filePath, NSError *error) {
//filePath就是文件路径
}];
[task resume];
网友评论