菜鸟教程小白 发表于 2022-12-11 19:41:52

ios - 我们可以将本地镜像设置为 SDWebImage 的离线图像吗?


                                            <p><p>我正在使用</p>

<pre><code>pod &#39;SDWebImage&#39;
</code></pre>

<p>要在我的应用程序中下载图像,我发现所有图像都下载到 <strong><em>“/Library/Caches/com.bundlename.bundlename/com.alamofire.imagedownloader/fsCachedData”</em></strong> 具有一些独特的名称。</p>

<p>我的应用程序具有离线支持,并且我已经使用文件路径(文件位于库缓存目录中)管理图像的 CoreData 实体,当我上传我的图像时,我的服务器将响应我的 S3 文件 URL 以供下载。</p>

<p>因为我(上传文件的用户)已经有一个图像文件,但 SDWebImage 不知道。所以它会再次下载文件。</p>

<p>有什么建议我应该怎么做才能在不再次下载相同图像的情况下对其进行管理?我无法在数据库中保留本地路径,因为我的应用具有与多个设备的同步功能。</p>

<p>谢谢</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>我认为您可以为此目的使用 SDImageCache。
示例代码:</p>

<pre><code>NSArray&lt;NSString*&gt; *urls = @&#34;aws s3 url here&#34;;
    [ diskImageExistsWithKey:urls completion:^(BOOL isInCache) {
      if ( isInCache ) {
             imageFromDiskCacheForKey:urls]];
      } else {
            NSURL *url = ;
            [yourImage sd_setImageWithURL:url completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
                [ storeImage:image forKey:urls toDisk:YES completion:^{

                }];
                ;
            }];
      }
    }] ;
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 我们可以将本地镜像设置为 SDWebImage 的离线图像吗?,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/44062389/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/44062389/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 我们可以将本地镜像设置为 SDWebImage 的离线图像吗?