ios – 来自Afnetworking的大图像缓存

ios – 来自Afnetworking的大图像缓存,第1张

概述我正在使用AFNetworking从互联网上下载一些图像到我的应用程序.我正在使用此代码下载这些图片, AFHTTPRequestOperation *requestOperation = [[AFHTTPRequestOperation alloc] initWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:_linkSt 我正在使用AFNetworking从互联网上下载一些图像到我的应用程序.我正在使用此代码下载这些图片,

AFhttpRequestoperation *requestoperation = [[AFhttpRequestoperation alloc] initWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:_linkString[indexPath.item]]]];requestoperation.responseSerializer = [AFImageResponseSerializer serializer];[requestoperation setCompletionBlockWithSuccess:^(AFhttpRequestoperation *operation,ID responSEObject) {    _imageVIEw = [[UIImageVIEw alloc] initWithFrame:CGRectMake(0,150,150)];    _imageVIEw.image = responSEObject;    } failure:^(AFhttpRequestoperation *operation,NSError *error) {        NSLog(@"Image error: %@",error);    }];[requestoperation start];

我注意到所有响应映像都是从此方法自动缓存到磁盘的.我的应用程序中也有这个选项.所有缓存的图像大小约为150kb.但是当我下载大约2MB大小的图像时,这些图像不会自动缓存到磁盘.

为什么小尺寸图像被缓存&大尺寸图像没有缓存?我是否使用错误的方法在AFNetworking中缓存图像?

任何人都可以使用AFNetworking为我提供缓存2MB图像的解决方案….

谢谢

解决方法 问题不在于AFNetworking,而在于NSURLCache.默认情况下,NSURLCache不会缓存大于10%的文件(不确定具体百分比是多少).

但增加缓存大小将有助于:

[[NSURLCache sharedURLCache] setMemoryCapacity:(20*1024*1024)];[[NSURLCache sharedURLCache] setdiskCapacity:(200*1024*1024)];
总结

以上是内存溢出为你收集整理的ios – 来自Afnetworking的大图像缓存全部内容,希望文章能够帮你解决ios – 来自Afnetworking的大图像缓存所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1010339.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-22
下一篇2022-05-22

发表评论

登录后才能评论

评论列表(0条)

    保存