Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios AFN网络中的大型图像缓存_Ios_Iphone_Objective C_Caching_Afnetworking - Fatal编程技术网

Ios AFN网络中的大型图像缓存

Ios AFN网络中的大型图像缓存,ios,iphone,objective-c,caching,afnetworking,Ios,Iphone,Objective C,Caching,Afnetworking,我正在使用AFNetworking将一些图像从互联网下载到我的应用程序中。我用这段代码下载这些图片 AFHTTPRequestOperation *requestOperation = [[AFHTTPRequestOperation alloc] initWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:_linkString[indexPath.item]]]]; requestOperation.responseSe

我正在使用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, 0, 150, 150)];
    _imageView.image = responseObject;

    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"Image error: %@", error);
    }];

[requestOperation start]; 
我注意到,所有的响应映像都是通过这个方法自动缓存到磁盘上的。我也希望在我的应用程序中使用该选项。所有缓存的图像大小约为150kb。但当我下载一个2MB大小的图像时,这些图像不会自动缓存到磁盘上

为什么缓存小尺寸图像和不缓存大尺寸图像??我是否使用了错误的方式在网络中缓存图像

有谁能给我一个解决方案来缓存2MB的图像使用AFNetworking以及


谢谢

问题不在于AFNetworking,而在于NSURLCache。默认情况下,NSURLCache不会缓存大于缓存大小10%(不确定确切百分比)的文件

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

[[NSURLCache sharedURLCache] setMemoryCapacity:(20*1024*1024)];
[[NSURLCache sharedURLCache] setDiskCapacity:(200*1024*1024)];

磁盘中应用程序的默认缓存大小是多少?&我应该在哪里使用这个[[NSURLCache sharedullcache]setDiskCapacity:(200*1024*1024)];密码?在AppDelegate中??我不熟悉URL缓存。很抱歉。不确定默认大小。我已将此代码放在我的AppDelegate
应用程序:didFinishLaunchingWithOptions: