0

my code looks like

if([[self cache] isEqualToNumber:[[NSNumber alloc] initWithInt:1]])
{
    [[NSURLCache sharedURLCache] setDiskCapacity:4 * 1024 * 1024];
    [[NSURLCache sharedURLCache] setMemoryCapacity:32 * 1024 * 1024];
    [self setRequestObj:[NSURLRequest requestWithURL:loadUrl cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0]];
}
else [self setRequestObj:[NSURLRequest requestWithURL:loadUrl cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60.0]];

My else part does not work. Why is my UIWebView not ignoring my local cache?

Every time I visited a testsite my app does not load from the original source. He only load the index.html but the linked images only at first visit.

What's my issue?

Premox
  • 183
  • 3
  • 23

2 Answers2

0

The NSURLRequestReloadIgnoringLocalCacheData flag affects only that one request, not future requests. So this works as expected. If you want to disable other caching, the only way I know of to do that is by implementing an NSURLProtocol that intercepts the HTTP/HTTPS requests, modifies them in an identifiable way (e.g. adding a custom header), and then re-sends them. This is not for the faint of heart.

You're probably better off just purging the cache: How to clear UIWebView cache?

Community
  • 1
  • 1
dgatwood
  • 9,519
  • 1
  • 24
  • 48
0

I had the same problem I think it is probably a UIWebView bug. Because after I changed it WKWebView, NSURLRequestReloadIgnoringLocalCacheData works!

Qiulang
  • 5,733
  • 4
  • 47
  • 82