我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设置了值。但是我不知道如何跟踪每个过程的进度并显示它。请帮帮我。