在我的应用程序中,我使用 ASINetworkQueue 方法下载文件。我有 n 个按钮,每个按钮单击不同的队列将使用多个请求创建,并开始异步下载(多次下载)。它工作正常,但我无法跟踪每个队列何时完成。我用过,
[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:)];
并将请求添加为,
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];
最后, [self.myQueue go];
委托方法是
- (void)queueComplete:(ASINetworkQueue *)queue
{
NSLog(@"Queue completed");
}
但它最后没有被调用。这里出了什么问题?任何想法?而且,如果有多个队列同时执行,我们如何区分最后哪个队列完成?
编辑:
- (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];
}
}
}
}