2

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];
4

2 に答える 2

0

操作を AFHTTPClient の operationQueue に追加するか、自分で作成した NSOperationQueue に追加する必要があります。

次に、使用するキューの最大同時操作数を 1 に設定します。

于 2013-08-12T10:55:49.733 に答える