相关疑难解决方法(0)

AlamofireImage磁盘缓存无法正常工作

我想使用AlamofireImage从URL下载图像,然后将其缓存在设备磁盘空间.我阅读了几篇关于此的帖子,发现AlamofireImage在ImageDownloader类的帮助下支持这一点.在这个SO答案中给出最有趣的信息

因此,我尝试为ImageDownloader设置自定义NSURLCache,以便将图像直接缓存到磁盘.我通过将内存容量设置为0来实现.然后我使用此自定义ImageDownloader下载图像.我为磁盘路径指定的文件夹是在磁盘上创建的,但不幸的是它保持为空并且图像不会以任何方式缓存.

**编辑:**重要的是要注意缓存的响应不会保存在缓存目录的文件夹中,而是保存在文件夹旁边的数据库文件中.

谁能告诉我这里我做错了什么?非常感谢阅读!

func diskImageDownloader(diskSpaceMB: Int = 100) -> ImageDownloader {

    let diskCapacity = diskSpaceMB * 1024 * 1024
    let diskCache = NSURLCache(memoryCapacity: 0, diskCapacity: diskCapacity, diskPath: "alamofireimage_disk_cache")
    let configuration = NSURLSessionConfiguration.defaultSessionConfiguration()
    configuration.URLCache = diskCache
    let downloader = ImageDownloader(configuration: configuration)
    UIImageView.af_sharedImageDownloader = downloader

    return downloader
}

func getProfileImage(atURL url: String, onComplete: SRServiceResponse<UIImage> -> Void) {
    guard let imageURL = NSURL(string: url) else
    {
        // TODO: Fail here
        return
    }

    let request = NSURLRequest(URL: …
Run Code Online (Sandbox Code Playgroud)

ios swift alamofire alamofireimage

7
推荐指数
2
解决办法
1677
查看次数

Alamofireimage 如何将图像保存到磁盘缓存?

我试图找出是否可以使用Alamofireimage强制将图像保存在磁盘上。查看源代码,我无法找到它实际将图像保存到磁盘的位置。有人知道吗?

image-caching ios diskcache swift alamofireimage

4
推荐指数
1
解决办法
3811
查看次数

af_setImageWithURL完成后如何将图像放入AutoPurgingImageCache?

imageView.af_setImageWithURL(URL)我想与AlamofireImageAutoPurgingImageCache一起使用。

如何通知我已af_setImageWithURL获取图像,以便将其放入缓存中?因为这是在后台完成的。

我更喜欢这样的东西:imageView.af_imageFromCache(URL)如果图像已经存在,则从缓存中设置图像,否则异步下载,然后设置图像并将其保存在缓存中。

caching image ios swift alamofire

1
推荐指数
1
解决办法
1750
查看次数