Tag: nsurlcache

如何使用NSURLSession和NSURLCache进行caching。 不工作

我有一个testing应用程序的设置,即使用户在下载过程中切换应用程序,也可以从networking上成功下载内容。 太棒了,现在我有了背景下载。 现在我想添加caching。 我不止一次下载图像,系统devise的B / C,给出一个图像的URL我可以告诉你,该url后面的内容将永远不会改变。 所以,现在我想caching我下载的结果,使用苹果公司内置的内存/磁盘caching,我已经读了这么多(而不是我在NSCachesDirectory手动保存文件,然后检查之前,请求,ick)。 为了获得caching在这个工作代码之上的工作,我添加了下面的代码: – (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. // Set app-wide shared cache (first number is megabyte value) [NSURLCache setSharedURLCache:[[NSURLCache alloc] initWithMemoryCapacity:60 * 1024 * 1024 diskCapacity:200 * 1024 * 1024 diskPath:nil]]; return YES; } 当我创build会话时,我添加了两个NEW行(URLCache和requestCachePolicy)。 // Helper method to get […]