相关疑难解决方法(0)

使用AFNetworking的setImageWithURL时如何配置缓存

我正在使用setImageWithURL我的应用程序下载一些图像.可能吗:

  1. 指定此图像必须在缓存中保留多长时间(例如1周)?
  2. 指定缓存的最大总大小有多大(例如200 MB)
  3. 看看图像缓存中有什么?
  4. 清除缓存?

关于这些问题,文件并不是很清楚.

caching objective-c ios5 afnetworking

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

iOS使用AFImageCache缓存图像似乎不起作用


我试图通过使用AFImageCache来缓存从URL加载的一些图像,但没有成功...我不确定如果我做错了什么并且如果你曾经使用过这个库就会喜欢你的意见.

我从NSURLRequest获取图像,然后按如下方式缓存它

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"];
Run Code Online (Sandbox Code Playgroud)

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

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

NSLog("%@", myIcon); // output (null)
Run Code Online (Sandbox Code Playgroud)

有关于此的任何想法或想法?谢谢.

caching nsdata ios afnetworking

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

标签 统计

afnetworking ×2

caching ×2

ios ×1

ios5 ×1

nsdata ×1

objective-c ×1