Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSURLRequest cache issue iOS 7

in iOS 7 cachePolicy doesn't work, it just cache the downloaded 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];

How can I disallow cache in iOS 7?

like image 987
Marckaraujo Avatar asked Dec 06 '22 05:12

Marckaraujo


1 Answers

I encountered the same problem and I verified that setting cachePolicy = 0 instead of cachePolicy = NSURLCacheStorageNotAllowed fixes the problem.

This doesn't make sense to me either since 0 corresponds to NSURLCacheStorageAllowed.
We can't just set it to 0 since Apple will probably fix this in a future release.
You might try calling:

[NSURLCache sharedURLCache] removeCachedResponseForRequest:yourRequest] just before initiating the request.

UPDATE: After further research I found that the code that broke has been using the wrong enum. Take a look at NSURLRequestCachePolicy in NSURLRequest.h. That's the one you need and it explains why setting to 0 fixed the problem for you.

like image 140
Dan Avatar answered Mar 16 '23 03:03

Dan