gpt4 book ai didi

ios - 能否将本 map 片设置为SDWebImage的离线图片?

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:10:33 32 4
gpt4 key购买 nike

我在用

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];
}];
}
}] ;

关于ios - 能否将本 map 片设置为SDWebImage的离线图片?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44062389/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com