NSURLRequest缓存问题iOS 7

Mar*_*ujo 4 nsurlrequest ios7 nsurlrequestcachepolicy

在iOS 7中,cachePolicy不起作用,它只是缓存下载的json.

//URLRequest
        NSString *url = [NSString stringWithFormat:@"http://www.semhora.com/jsonparser/categories/categories_%d_test.json", _categoriesIndex];
        NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:url]
                                                  cachePolicy:NSURLCacheStorageNotAllowed
                                          timeoutInterval:60.0];
Run Code Online (Sandbox Code Playgroud)

如何在iOS 7中禁止缓存?

Dan*_*Dan 7

我遇到了同样的问题,我验证了设置,cachePolicy = 0 而不是cachePolicy = NSURLCacheStorageNotAllowed修复问题.

这对我来说没有意义,因为0对应于NSURLCacheStorageAllowed.
我们不能将其设置为0,因为Apple可能会在未来版本中修复此问题.
您可以尝试致电:

[NSURLCache sharedURLCache] removeCachedResponseForRequest:yourRequest] 就在发起请求之前.

更新:经过进一步研究后,我发现破坏的代码一直使用错误的枚举.查看NSURLRequest.h中的NSURLRequestCachePolicy.这就是你需要的那个,它解释了为什么设置为0为你解决问题.


Mar*_*ujo 6

我刚用过:

//URLRequest
        NSString *url = [NSString stringWithFormat:@"http://www.semhora.com/jsonparser/categories/categories_%d_test.json", _categoriesIndex];
        NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:url]
                                                  cachePolicy:0
                                          timeoutInterval:60.0];
Run Code Online (Sandbox Code Playgroud)

现在它有效,从苹果开发论坛得到任何答案,直到现在它为什么会发生.