1

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]);
}
Mithuzz
  • 1,091
  • 14
  • 43

2 Answers2

1

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

CarlJ
  • 9,461
  • 3
  • 33
  • 47
  • i have tried this, but nothing is happening. I have updated my question with the code that I have used. – Mithuzz Apr 27 '12 at 04:46
1

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/

Eric
  • 4,063
  • 2
  • 27
  • 49