Ios dataWithContentsOfURL缓存吗?
我试图确定Ios dataWithContentsOfURL缓存吗?,ios,objective-c,image,caching,Ios,Objective C,Image,Caching,我试图确定dataWithContentsOfURL是否缓存内容,以便在代码中: UIImage *img = [UIImage imageWithData:[NSData dataWithContentsOfURL: [NSURL URLWithString:[NSString stringWithFormat:@"http://testsite.com/img/%@.png" ,imgName]]]]; 下面是一行: UIImage *img2 = [UIImage imageWithDa
dataWithContentsOfURL
是否缓存内容,以便在代码中:
UIImage *img = [UIImage imageWithData:[NSData dataWithContentsOfURL:
[NSURL URLWithString:[NSString stringWithFormat:@"http://testsite.com/img/%@.png"
,imgName]]]];
下面是一行:
UIImage *img2 = [UIImage imageWithData:[NSData dataWithContentsOfURL:
[NSURL URLWithString:[NSString stringWithFormat:@"http://testsite.com/img/%@.png"
,imgName]]]];
是否需要再次访问网络?这不是缓存
我建议您开始使用ASIHTTPRequest或AFNetwork框架。它们允许您缓存
如果使用NSMutableURLRequest,可以使用一些缓存方法,但不是很好的方法
您也不应该使用XWithContentOfURL,因为它们会占用您的主线程,除非您使用threads或GCD,如果您使用上述框架,您可以免费获得这些内容您可以保存并使用NSDataoov。。稍等一下,2个具有相同图像内容的UIImage需要什么?您可以在任何地方使用相同的图像,对吗?只有在运行时决定后续请求时才会调用img2。URL也在运行时结束。我想知道如果我的应用程序碰巧访问同一个URL两次,它是否需要再次访问网络。