Mithuzz
Mithuzz

Reputation: 1091

How to show multiple download progress using ASINetworkQueue

I want to perform the downloads on multiple button clicks and these are buttons are created dynamically. And each button is assigned with different urls.

I want to perform multiple download operations at the same time, and also want to update the download progress of each download on different UIProgressViews.

I was told that to use ASINetworkQueue method, but in this one, how can I add requests dynamically to the queue? Or is there any other way or sample code?

Please help.

Sample code:

- (void)fetchThisURLFiveTimes:(NSURL *)url
{
   [myQueue cancelAllOperations];
   [myQueue setDownloadProgressDelegate:myProgressIndicator];
   [myQueue setDelegate:self];
   [myQueue setRequestDidFinishSelector:@selector(queueComplete:)];
   int i;
   for (i=0; i<5; i++) {
      ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
      [myQueue addOperation:request];
   }
   [myQueue go];
}

- (void)queueComplete:(ASINetworkQueue *)queue
{
   NSLog(@"Value: %f", [myProgressIndicator progress]);
}

Upvotes: 1

Views: 1234

Answers (2)

Eric
Eric

Reputation: 4061

I believe ASI has stopped being supported. My company has started using RestKit as an alternative, FYI. See the header at the top of his page: http://allseeing-i.com/ASIHTTPRequest/

Upvotes: 1

CarlJ
CarlJ

Reputation: 9481

simple add new Operations/Requests to the queue:

  [networkQueue addOperation:<#(NSOperation *)#>]
  [networkQueue addOperations:<#(NSArray *)#> waitUntilFinished:<#(BOOL)#>]

and you can track the progress for an specific Request by setting the:

  [request setDownloadProgressDelegate:<#(id)#>]

// If the downloadProgressDelegate is an NSProgressIndicator, we set its MaxValue to 1.0 so we can update it as if it were a UIProgressView

Upvotes: 1

Related Questions