[英]AFImageRequestOperation with SDWebImage issue
我使用AFImageRequestOperation下載一些圖標,同時使用SDWebImage下載一些主視圖照片。 每個AFImageRequestOperation都添加到我在應用程序委托中定義的publicOperationQueue中,其maxConcurrentOperationCount設置為10。奇怪的是,有時我的10個以上圖標中的一兩個會被主視圖中的某些圖片代替,應由SDWebImage下載。 並且當我設置一個大於圖標計數的maxConcurrentOperationCount時,它可以正常工作。 我懷疑這是否與共享一些資源和maxConcurrentOperationCount的多個NSOperationQueue有關。 有人可以幫忙嗎?
//below is the icon downloading code
//============================//
for(NSString *url in picUrls)
{
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]];
[urlRequest setHTTPShouldHandleCookies:NO];
[urlRequest addValue:@"image/*" forHTTPHeaderField:@"Accept"];
AFImageRequestOperation *requestOperation = [[AFImageRequestOperation alloc] initWithRequest:urlRequest];
[requestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject){
NSString *imageName = trimNilOrNuLL([url lastPathComponent]);
if(imageName.length > 0)
{
NSData *imageData = UIImagePNGRepresentation(responseObject);
[imageData writeToFile:[path stringByAppendingPathComponent:imageName] atomically:YES];
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error){
NSLog(@"%@",error);
}];
[[AppShare appDelegate].publicOperationQueue addOperation:requestOperation];
}
//============================//
對於SDWebImage,我在UIImageView + WebCache類別中使用-(void)setImageWithURL:(NSURL *)url方法來下載圖片
好的,從發現您正在使用AFNetworking的問題開始。然后進行圖像下載,為什么不使用AFNetworking的UIImageView Extension? 您不必為此實現任何隊列或任何代碼,我認為這樣就足夠了
[self.imageview setImageWithURL:url placeholderImage:nil];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.