NSUrlCache removeCachedResponseForRequest:目标c中的requestImage实现

时间:2017-05-16 05:07:29

标签: objective-c nsurlsession nsurlcache

我想在NSUrlCache.How中存储从请求中获取的响应。怎么办呢?

-(void)sendRequestForImage

{  

    NSCachedURLResponse * cachedResponse = [Cache cachedResponseForRequest:requestImage];

    if(!cachedResponse.data)

    {
     NSString*imageStr=[NetworkManger getImage:requestImage]; 
        _imageView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:imageStr]]];

    }

    else

    { 
        NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:cachedResponse.data options:NSJSONReadingAllowFragments error:nil];    


      }   
}

现在我正在尝试删除请求requestImage的对象,我尝试按以下方式执行此操作:

- (IBAction)clearImage:(id)sender {

    [Cache removeCachedResponseForRequest:requestImage];
   }

但这不起作用。为什么呢?

0 个答案:

没有答案