我正在从下面的代码下载多个图像并保存到数据库。但是对于某些图像,我遇到了错误。
错误:ImageIO:PNG 无效距离太远错误:ImageIO:PNG 数据检查不正确
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
dispatch_async(queue, ^{
NSString *imgStr = [dict objectForKey:@"image"];
imgStr = [imgStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSData *imgData = [NSData dataWithContentsOfURL:[NSURL URLWithString:imgStr]];
UIImage *image = [UIImage imageWithData:imgData];
dispatch_sync(dispatch_get_main_queue(), ^{
mYImageView.image = image;
});
});
如何检查存储的图像是否有效,以便我可以再次下载图像?