iOS使用AFImageCache缓存图像似乎不起作用 [英] iOS Caching images with AFImageCache doesn't seem to work

查看:76
本文介绍了iOS使用AFImageCache缓存图像似乎不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在尝试使用AFImageCache缓存从URL加载的某些图像,但没有成功...我不确定如果我做错了什么,并且愿意在您的意见下您曾经使用过该库。


I'm trying to cache some images loaded from a URL by using AFImageCache, without success... I'm not sure If i'm doing anything wrong and would love your opinions if you've ever used this library.

我从NSURLRequest获取图像,然后将其缓存如下

I'm getting an image from a NSURLRequest, and then caching it as follows

UIImage *img; //This image is a png icon returned from the server
NSData *imgData = UIImagePNGRepresentation(img); // Always checking length to make sure its more than 0, and it is

[[AFImageCache sharedImageCache] cacheImageData: imgData
                                         forURL: myURL
                                      cacheName: @"IconCache"];

在下一次运行中,我将尝试检查图像是否已缓存,但始终会得到 nil 由于某些原因。

On the next run, i'll try to check if the image was cached, but will always get nil for some reason.

UIImage *myIcon = [[AFImageCache sharedImageCache] cachedImageForURL: myURL cacheName: @"IconCache"];

NSLog("%@", myIcon); // output (null)

对此有任何想法或想法吗?
谢谢。

Any ideas or thoughts about this? Thanks.

推荐答案

您正在使用哪个版本的AFNetworking? AFImageCache 很久以前已从公共API中删除。如果要进行图像缓存,请使用 NSURLCache ,它可以在系统级别缓存所有网络响应。 AFImageCache 一直只是一个临时缓存,用于提高滚动视图中图像加载的性能。

What version of AFNetworking are you using? AFImageCache was removed from the public API a long time ago. If you want to do image cacheing, use NSURLCache, which caches all network responses on a system level. AFImageCache has always just been a temporary cache used to improve the performance of image loading in scroll views.

这篇关于iOS使用AFImageCache缓存图像似乎不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆