iOS Caching images with AFImageCache doesn't seem to work

微笑、不失礼 提交于 2019-12-06 16:13:23

问题



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.

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

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.


回答1:


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.



来源:https://stackoverflow.com/questions/10469832/ios-caching-images-with-afimagecache-doesnt-seem-to-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!