我正在使用
pod 'SDWebImage'
为了在我的应用程序中下载图像,我发现所有图像都下载在"/Library/Caches/com.bundlename.bundlename/com.alamofire.imagedownloader/fsCachedData">中,并带有一些唯一的名称。
我的应用程序具有离线支持,并且我已经管理了具有文件路径的图像的 CoreData 实体(文件位于库缓存目录中(,当我上传图像时,我的服务器将使用我的 S3 文件 URL 进行响应以进行下载。
因为我(上传文件的用户(已经有一个图像文件,但 SDWebImage 不知道。因此,它将再次下载该文件。
任何建议我应该怎么做才能在不再次下载相同图像的情况下管理它?我无法在我的数据库中保留本地路径,因为我的应用程序具有与多个设备的同步功能。
谢谢
我认为你可以使用SDImageCache来实现这个目的。示例代码:
NSArray<NSString*> *urls = @"aws s3 url here";
[[SDImageCache sharedImageCache] diskImageExistsWithKey:urls[0] completion:^(BOOL isInCache) {
if ( isInCache ) {
[yourImage setImage:[[SDImageCache sharedImageCache] imageFromDiskCacheForKey:urls[0]]];
} else {
NSURL *url = [NSURL URLWithString:item.url];
[yourImage sd_setImageWithURL:url completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
[[SDImageCache sharedImageCache] storeImage:image forKey:urls[0] toDisk:YES completion:^{
}];
[yourImage setImage:image];
}];
}
}] ;