Reputation: 613
I am using AFDownloadRequestOperation
for downloading. i am unable to track the progress of the each download that is in the queue. My progress bar show the progress of the operation on the main thread(which is the last added request). Referred to the many links but was not able to track the progress for the whole block. Here's the code
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];
}
i know that i am getting the same progress because of the
totalBytesReadForFile = self.DownloadComplete;
totalBytesExpectedToReadForFile = self.DownloadSize;
as they set the value for my progressView. But i am out of ideas how to track progress for each process and display it. Help me please.
Upvotes: 0
Views: 1526
Reputation: 19544
Use AFHTTPClient -enqueueBatchOfHTTPRequestOperations:progressBlock:completionBlock:
to track the progress of operations within a batch. As each operation is completed, you can increment your progress block to reflect it (e.g. "5 or 19 operations finished").
Tracking cumulative byte accumulation for all operations is probably unnecessary; the aforementioned approach sufficiently communicates progress to the user.
Upvotes: 1