在 ios 6 中,我有一个调用 sendAsynchronousRequest 的图像下载器方法。当图像数量过多时,永远不会调用完成块,并且永远不会破坏超过 60 个工作线程(因此永远不会完成图像下载)。在 ios 7 中,它似乎工作正常。你是如何完成这项工作的?代码如下
for(NSDictionary * imageDict in thumbnailJSONArray){
NSString * thumbNailString = [imageDict objectForKey:JSON_URL];
//other codes..
[self downLoadThumbNails:numbertoAdd urlRequest:thumbNailString];
}
-(void)downLoadThumbNails:(NSUInteger) numberToAdd urlRequest:(NSString*)urlString {
if(self.imageQueue == nil){
self.imageQueue = [[NSOperationQueue alloc] init];
}
[NSURLConnection sendAsynchronousRequest:urlRequest queue:self.imageQueue completionHandler:^(NSURLResponse *response, NSData* data, NSError *connectionError) {
//image setting codes
}];
}
--EDIT-- 更清楚一点,从不调用图像设置代码,因此从不设置下载的图像。