【发布时间】:2011-10-30 18:36:35
【问题描述】:
我正在通过ASINetworkQueue 下载一堆图像。我在模拟器中没有问题,但在 iPad 上,一些图像(每次都不同)没有下载。我该如何解决这个问题?
代码如下:
队列创建:
if (addedPaintings > 0) {
[currentPaintingsArray addObjectsFromArray:objectsToAdd];
[unseenPaintings addObjectsFromArray:objectsToAdd];
[self downloadImages];
}
// update plist file if data was altered.
if (addedPaintings > 0 || removedPaintings > 0)
[currentPaintingsArray writeToFile:dataFilePath atomically:YES];
else
[self completeSync:request.responseStatusCode];
}
图片下载方式:
- (void) downloadImages {
[networkQueue reset];
[networkQueue setDelegate:self];
[networkQueue setShowAccurateProgress:YES];
[networkQueue setDownloadProgressDelegate:self.progressView.customView];
[networkQueue setQueueDidFinishSelector:@selector(imageQueueDownloadComplete:)];
for (NSDictionary *dict in [Globals sharedGlobals].unseenPaintings) {
NSString *link = [dict objectForKey:@"link"];
NSString *smallLink = [dict objectForKey:@"smallLink"];
if ([link length] != 0) {
NSURL *url = [NSURL URLWithString:[[URL stringByAppendingString:GALLERY] stringByAppendingString: link]];
ASIHTTPRequest *downloadRequest = [[ASIHTTPRequest alloc] initWithURL:url];
[downloadRequest setDownloadDestinationPath:[documentsDirectory stringByAppendingPathComponent:link]];
[downloadRequest setDidFailSelector:@selector(imageDownloadFailed:)];
[downloadRequest setDidFinishSelector:@selector(imageDownloadComplete:)];
[downloadRequest setUserInfo:dict];
[downloadRequest setDelegate:self];
[networkQueue addOperation:downloadRequest];
[downloadRequest release];
NSURL *urlCarousel = [NSURL URLWithString:[[URL stringByAppendingString:WS_IMAGES] stringByAppendingString: smallLink]];
downloadRequest = [[ASIHTTPRequest alloc] initWithURL:urlCarousel];
[downloadRequest setDownloadDestinationPath:[documentsDirectory stringByAppendingPathComponent:smallLink]];
[downloadRequest setDidFailSelector:@selector(imageDownloadFailed:)];
[downloadRequest setUserInfo:dict];
[downloadRequest setDelegate:self];
[networkQueue addOperation:downloadRequest];
[downloadRequest release];
}
}
[networkQueue go];
}
【问题讨论】:
-
你遇到了什么错误,你已经做了什么来调查这个,等等?
-
我没有收到任何错误。我只是没有看到一些图像。我的猜测是,这个 ASINetworkQueue 有时会用另一个图像文件覆盖一个图像文件。
-
我们只能猜测,因为您没有向我们展示代码。
-
对不起,我现在发布代码。另外,如果我将下载方法从 networkQueue 更改为 [downloadRequest startAsynchronous],一切正常。
标签: ios asihttprequest