AFDownloadRequestOperation + AFNetworking を使用して、サーバーからファイルのリストをダウンロードして再開しています。このコードは、一度に複数のファイルをダウンロードして再開するのにうまく機能しています。しかし、操作キュー内のすべての操作をキューに入れ、操作を 1 つずつ実行する方法は?
これが私の現在のコードです
// 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];