我正在使用AFDownloadRequestOperation
进行下载。我无法跟踪队列中每个下载的进度。我的进度条显示主线程上的操作进度(这是最后添加的请求)。提到了很多链接,但无法跟踪整个块的进度。这是代码
for (int i =0; i<count; i++)
{
VideoClass *item1=[[VideoClass alloc]initWithVideo:[self.Downloads objectAtIndex:i]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:item1.URL]];
NSString *videoTgtPath = [[[[VideoDBClass alloc] init] autorelease] getPathToVideoFile:[self.Downloads objectAtIndex:i]];
AFDownloadRequestOperation *operation = [[AFDownloadRequestOperation alloc] initWithRequest:request targetPath:videoTgtPath shouldResume:YES];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Successfully downloaded file to %@", videoTgtPath);
if ([[[[VideoDBClass alloc] init] autorelease] completeDownload:item1 error:nil])
{
NSLog(@"Successfully Moved ");
}
self.AllDownLoads = [[[[VideoDBClass alloc] init] autorelease] getVideos];
[DownloadTblView reloadData];
}
failure:^(AFHTTPRequestOperation *operation, NSError *error)
{
NSLog(@"Error: %@", error);
}];
[operation setProgressiveDownloadProgressBlock:^(AFDownloadRequestOperation *operation1,NSInteger bytesRead, long long totalBytesRead, long long totalBytesExpected, long long totalBytesReadForFile, long long totalBytesExpectedToReadForFile)
{
totalBytesReadForFile = self.DownloadComplete;
totalBytesExpectedToReadForFile = self.DownloadSize;
NSLog(@"the name of the operation is %@",operation1.request.URL.absoluteString);
NSLog(@"Operation%i: bytesRead: %d", 1, bytesRead);
NSLog(@"Operation%i: totalBytesRead: %lld", 1, totalBytesRead);
NSLog(@"Operation%i: totalBytesExpected: %lld", 1, totalBytesExpected);
NSLog(@"Operation%i: totalBytesReadForFile: %lld", 1, totalBytesReadForFile);
NSLog(@"Operation%i: totalBytesExpectedToReadForFile: %lld", 1, totalBytesExpectedToReadForFile);
// My PROGRESS View in the this section of the tableview and get updated by reloading this section But it shows the same progress for all downloads.
[DownloadTblView reloadSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationNone];
}];
// [operation addObject:operation];
[operation start];
}
我知道我因为
而取得了同样的进步 totalBytesReadForFile = self.DownloadComplete;
totalBytesExpectedToReadForFile = self.DownloadSize;
因为他们为我的progressView设置了值。但我没有想法如何跟踪每个流程的进度并显示它。请帮帮我。
答案 0 :(得分:1)
使用AFHTTPClient -enqueueBatchOfHTTPRequestOperations:progressBlock:completionBlock:
跟踪批次内的操作进度。每个操作完成后,您可以增加进度块以反映它(例如“完成5或19次操作”)。
跟踪所有操作的累积字节累积可能是不必要的;上述方法充分地将进展传达给用户。