使用AFNetworking 1.0下载1.x MB大小的视频文件需要30秒以上

时间:2014-02-13 07:08:40

标签: objective-c ios7 afnetworking

我使用下面的代码从我的设备上的服务器下载视频文件,但下载1.5 MB大小的文件需要30秒以上。有没有办法加快这个下载过程? 我们可以将整个视频文件分成块并同时下载吗?

AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:videoURL]];

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:videoURL]];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];

NSString *outputPath = [[NSString alloc] initWithFormat:@"%@%@", NSTemporaryDirectory(), @"m.mp4"];
operation.outputStream = [NSOutputStream outputStreamToFileAtPath:outputPath append:NO];

[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {

    NSLog(@"Successfully downloaded file to %@", outputPath);

} failure:^(AFHTTPRequestOperation *operation, NSError *error) {

    NSLog(@"Error downloading file");

}];

[httpClient enqueueHTTPRequestOperation:operation];

0 个答案:

没有答案