我需要在队列中下载多个文件。当我尝试下载单个文件时,它工作得很好,但是当我尝试下载多个文件时,它在第一次下载的同时开始下载,我需要将它们排在队列中,直到第一次下载完成,然后再进行第二次下载。我正在使用 AFNetworking 库扩展 AFDownloadRequestOperation。下面是我的代码。如果我做错了什么,请帮助我。
NSURLRequest *request = [NSURLRequest requestWithURL:videoURL];
AFDownloadRequestOperation *operation = [[AFDownloadRequestOperation alloc] initWithRequest:request targetPath:path shouldResume:YES];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
if(operation.response.statusCode == 200) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Alert" message:@"Successfully Downloaded" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
}
}failure:^(AFHTTPRequestOperation *operation, NSError *error) {
if(operation.response.statusCode!= 200) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Alert" message:@"Error While Downloaded" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
}
}];
[operation setProgressiveDownloadProgressBlock:^(NSInteger bytesRead, long long totalBytesRead, long long totalBytesExpected, long long totalBytesReadForFile, long long totalBytesExpectedToReadForFile) {
float percentDone = ((float)totalBytesRead) / totalBytesExpectedToReadForFile;
delegate.progressDone = percentDone;
[progressTableView reloadData];
}];
[operation start];