Summary: I want to track the progress of downloading files with progress bars inside the table cells. I am using ASIHTTPRequest in ASINetworkQueue to handle downloads.
It works, but the progress indicators remain at 0% and immediately go to 100% at the end of each download.
Details: I configured my ASIHTTPRequest and ASINetworkQueue requests as follows:
[Only extracting my code]
- (void) startDownloadOfFiles:(NSArray *) filesArray { for (FileToDownload *aFile in filesArray) { ASIHTTPRequest *downloadAFileRequest = [ASIHTTPRequest requestWithURL:aFile.url]; UIProgressView *theProgressView = [[UIProgressView alloc] initWithFrame:CGRectMake(20.0f, 34.0f, 280.0f, 9.0f)]; [downloadAFileRequest setDownloadProgressDelegate:theProgressView]; [downloadAFileRequest setUserInfo: [NSDictionary dictionaryWithObjectsAndKeys:aFile.fileName, @"fileName", theProgressView, @"progressView", nil]]; [theProgressView release]; [downloadAFileRequest setDelegate:self]; [downloadAFileRequest setDidFinishSelector:@selector(requestForDownloadOfFileFinished:)]; [downloadAFileRequest setDidFailSelector:@selector(requestForDownloadOfFileFailed:)]; [downloadAFileRequest setShowAccurateProgress:YES]; if (! [self filesToDownloadQueue]) { // Setting up the queue if needed [self setFilesToDownloadQueue:[[[ASINetworkQueue alloc] init] autorelease]]; [self filesToDownloadQueue].delegate = self; [[self filesToDownloadQueue] setMaxConcurrentOperationCount:2]; [[self filesToDownloadQueue] setShouldCancelAllRequestsOnFailure:NO]; [[self filesToDownloadQueue] setShowAccurateProgress:YES]; } [[self filesToDownloadQueue] addOperation:downloadAFileRequest]; } [[self filesToDownloadQueue] go]; }
Then, in the UITableViewController, I create the cells and add the file name and UIProgressView using the objects stored in the userInfo dictionary of the request.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"fileDownloadCell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { [[NSBundle mainBundle] loadNibNamed:@"FileDownloadTableViewCell" owner:self options:nil]; cell = downloadFileCell; self.downloadFileCell = nil; } NSDictionary *userInfo = [self.fileBeingDownloadedUserInfos objectAtIndex:indexPath.row]; [(UILabel *)[cell viewWithTag:11] setText:[NSString stringWithFormat:@"%d: %@", indexPath.row, [userInfo valueForKey:@"fileName"]]];
A progress bar has been added, with progress reaching 0%. Then, at the end of the download, they instantly switch to 100%.
Some downloads are very large (over 40 MB).
I do not do anything complicated in threads.
Reading the ASIHTTPRequest forums, it seems I am not alone, but I could not find a solution. Am I missing something? Is this a bug in ASI *?
Guillaume
source share