我使用AFDownloadRequestOperation + AFNetworking下载和从服务器恢复的文件列表。该代码一次很好地下载和恢复多个文件。但是,如何将操作队列中的所有操作排队并逐个执行操作?下载多个文件AFDownloadRequestOperation
这里是我当前的代码
// request the video file from server
NSString *downloadURL = [NSString stringWithFormat:@"%@%@", [recipe download_url], [step valueForKey:@"video"]];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:downloadURL]];
AFDownloadRequestOperation *operation = [[AFDownloadRequestOperation alloc] initWithRequest:request targetPath:videoFile shouldResume:YES];
// done saving!
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Done downloading %@", videoFile);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %ld", (long)[error code]);
}];
// set the progress
[operation setProgressiveDownloadProgressBlock:^(AFDownloadRequestOperation *operation, NSInteger bytesRead, long long totalBytesRead, long long totalBytesExpected, long long totalBytesReadForFile, long long totalBytesExpectedToReadForFile) {
float progress = ((float)totalBytesReadForFile)/totalBytesExpectedToReadForFile;
[progressBar setProgress:progress];
}];
[operation start];