cocoa touch - Accurate progress displayed with UIProgressView for ASIHTTPRequest in an ASINetworkQueue -


summary: want track progress of file downloads progress bars inside cells of tableview. i'm using asihttprequest in asinetworkqueue handle downloads.
works, progress bars stay @ 0%, , jump directly @ 100% @ end of each download.


details: set asihttprequest requests , asinetworkqueue way:

[only extract of code]

- (void) startdownloadoffiles:(nsarray *) filesarray {      (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 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 uitableviewcontroller, create cells, , add name of file , uiprogressview using objects stored in userinfo dictionary of 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"]]];      // here, i'm removing previous progress view, , adding cell     [[cell viewwithtag:12] removefromsuperview];     uiprogressview *theprogressview = [userinfo valueforkey:@"progressview"];     if (theprogressview) {         theprogressview.tag = 12;         [cell.contentview addsubview:theprogressview];     }        return cell; } 

the progress bar added, progress set 0%. then, @ end of download, instantly jump 100%.

some of download big (more 40mb).

i not tricky threads.

reading forums of asihttprequest, seems i'm not alone, couldn't find solution. missing obvious? bug in asi* ?

asihttprequest can report progress if server sending content-length: headers, otherwise doesn't know how big response be. (asinetworkqueue sends head requests @ start try figure out document sizes.)

try collecting network traffic charlesproxy or wireshark, see if these headers present and/or happening head requests.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -