使用AFImageCachecaching图像似乎不起作用
我试图通过使用AFImageCachecaching一些图像加载从一个URL,没有成功…我不知道如果我做错了什么,并会喜欢你的意见,如果你曾经使用过这个库。
我从NSURLRequest获取图像,然后如下caching它
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"];
在下一次运行中,我会尝试检查图像是否被caching,但由于某种原因将总是变为nil
。
UIImage *myIcon = [[AFImageCache sharedImageCache] cachedImageForURL: myURL cacheName: @"IconCache"]; NSLog("%@", myIcon); // output (null)
任何想法或想法呢? 谢谢。
你使用的是什么版本的AFNetworking? AFImageCache
以前, AFImageCache
已经从公共API中被移除了。 如果要执行映像caching,请使用NSURLCache
,它在系统级别caching所有networking响应。 AFImageCache
一直是一个临时caching,用于提高滚动视图中图像加载的性能。