How to track download progress using ASIHTTPRequest (ASYNC)

I am currently using the asynchronous call of my API (I setup) on my site. I am using ASIHTTPRequest setDownloadProgressDelegate with a UIProgressView. However, I do not know what I can call a selector (updateProgress), which will set the progress of CGFloat to progressView progress. I tried the following, but both progresses were zero. Please tell me how can I do this?

(in some method) ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:[url stringByAppendingFormat:@"confidential"]]]; [request setDownloadProgressDelegate:progressView]; [NSTimer scheduledTimerWithTimeInterval:1.0f/60.0f target:self selector:@selector(updateProgress:) userInfo:nil repeats:YES]; [request setCompletionBlock:^{~100 lines of code}]; [request setFailedBlock:^{~2 lines of code :) }]; [request startAsynchronous]; - (void) updateProgress:(NSTimer *)timer { if (progressView.progress < 1.0) { currentProgress = progressView.progress; NSLog(@"currProg: %f --- progressViewProg: %f", currentProgress, progressView.progress); } else { [timer invalidate]; } return; } 
+4
source share
3 answers

Try adding to your query:

 [request setShowAccurateProgress:YES]; 

This will not help you call updateProgress , ASIHTTPRequest will change the progress bar itself.

+4
source

For people who still find this answer: Note that ASI is very outdated, you should use NSURLSession or ASIHTTPRequest instead.

One way to achieve what you want is to set downloadProgressDelegate as your own class and implement setProgress: In this implementation, update the progress variable, and then call [progressView setProgress:];

Or, in the code, configure the delegate to execute the request load request:

 [request setDownloadProgressDelegate:self]; 

and then add the method to your class:

 - (void)setProgress:(float)progress { currentProgress = progress; [progressView setProgress:progress]; } 
+7
source

BTW: NS * Connecting at boot is a little faster than ASI * .

In any case, the example on this page implies that you do not need to manually β€œcopy” the value from the download object to the progress view object.

In fact, your timer-based code gets progress from the progress view, which should show progress already. This code should not have a timer at all, if I understand ASIHTTP * correctly.

0
source

All Articles