Reputation: 479
In my application i am using ASINetworkQueue method for downloading files. I have n number of buttons and for each button click different Queues will be created with multiple Requests, and starts download asynchronously (multiple download). It is working fine, but I couldn't track when each Queue completes. I have used,
[self.myQueue cancelAllOperations];
[self.myQueue setDownloadProgressDelegate:currentProgress];
[self.myQueue setDelegate:self];
[self.myQueue setShowAccurateProgress:YES];
[self.myQueue setRequestDidFinishSelector:@selector(requestFinished:)];
[self.myQueue setQueueDidFinishSelector:@selector(queueComplete:)];
and added requests as,
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:str]];
[request setDownloadProgressDelegate:currentProgress];
[request setShowAccurateProgress:YES];
[request setDelegate:self];
[request shouldContinueWhenAppEntersBackground];
[request allowResumeForFileDownloads];
[request startAsynchronous];
[self.myQueue addOperation:request];
and last, [self.myQueue go];
and the delegate method is
- (void)queueComplete:(ASINetworkQueue *)queue
{
NSLog(@"Queue completed");
}
but its not called at the end. What went wrong here? Any idea? And also, if there are multiple Queues performing at the same time, how can we differentiate which queue is completed at the end?
Edit:
- (void)download{
UIImageView *image = (UIImageView *)[mainView viewWithTag:selectedTag];
for (UIProgressView *currentProgress in [image subviews]) {
if ([currentProgress isKindOfClass:[UIProgressView class]]) {
NSLog(@"Prog tag: %d",currentProgress.tag);
if(currentProgress)
{
currentProgress.progress = 0.0;
[[self myQueue] cancelAllOperations];
[self setNetworkQueue:[ASINetworkQueue queue]];
[[self myQueue] setDownloadProgressDelegate:currentProgress];
[[self myQueue] setDelegate:self];
[[self myQueue] setShowAccurateProgress:YES];
ASIHTTPRequest *request;
[myQueue setQueueDidFinishSelector:@selector(queueComplete:)];
for (int h = 0; h < [urlArray count]; h++) {
request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:[urlArray objectAtIndex:h]]];
[[self myQueue] addOperation:request];
}
[[self myQueue] go];
}
}
}
}
Upvotes: 1
Views: 1394
Reputation: 27620
You are starting the request before adding it to the queue.
[request startAsynchronous];
The starting of the request should only be handled by the queue. So remove that line and the complete callback should be called.
When you have more than one queue, you should keep a reference to each queue. You could put them in an NSMutableArray. Then in the complete callback you can check which queue is complete by checking them against the queues in your array.
EDIT:
It seems that you forget to set your myQueue
iVar, so it was nil
and ignored all method calls. So add:
self.myQueue = [ASINetworkQueue queue];
To have more than one queue in an array:
self.queues = [NSMutableArray array] // queues is a retained property
ASINetworkQueue *queue = [ASINetworkQueue queue];
[queues addObject:queue];
Upvotes: 1