0

I've got an app with UIWebView which is used to load local files. I've created a custom URL protocol, which I use to do some stuff with the data passed to the web view, and in startLoading I've added:

[self.client URLProtocol:self didReceiveResponse:response cacheStoragePolicy:NSURLCacheStorageNotAllowed];

Also when starting the app, I've disabled the cache using this piece of code:

NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:0 diskCapacity:0 diskPath:nil];
[NSURLCache setSharedURLCache:sharedCache];
sharedCache = nil;

but unfortunately, the damn thing still allows for caching local files.

When I close the web view and open it again, the javascript files are not loaded again through my url protocol.

What else should I set to make it work?

My goal is to always load files through the custom url protocol, and not only the first time.

For me, the startLoading method in NSURLProtocol is not called for subsequential requests.

Krystian
  • 3,193
  • 2
  • 33
  • 71

1 Answers1

0

I suspect the issue is that UIWebView doesn't know or care what the underlying network protocol says about caching, because the caching isn't happening at the NSURL level. You also need to send/inject fake Cache-control headers so that WebKit won't cache it at that level.

dgatwood
  • 10,129
  • 1
  • 28
  • 49