2

I am using UIWebView to display an HTML page inside an IOS app. The HTML page contains a png file that I create on the local disk and write to. Everything works fine the first time I display the page, but when I try to create a new image and redisplay the page, the original image is displayed.

The issue appears to be that I am using the same file name for the PNG file. Even though I write to the PNG file with a new image, the UIWebView is caching the image from the original load, and displays the original image, not the new one. I have verified that the new image is being written to correctly by loading it into Safari.

So how can I clear the UIWebView's cache of this image? I realize that another option would be to give the png file a different file name each time I create it, but then I'd either accumulate png files or I'd have to add code to clear out the png files when done - which I'd rather not do.

Dave
  • 146
  • 1
  • 10

2 Answers2

0

Have a look at this answer:

NSString *testURL = [NSString stringWithFormat:@"%@?t=%@", url, randQuery];
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:testURL] cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:10.0]];
Community
  • 1
  • 1
lootsch
  • 1,867
  • 13
  • 21
  • Sorry, I'm not following. I am putting static html into the UIWebView. There is no URL, per se. The static HTML has an tag in it, and the xx.png file is getting cached. It looks like you're saying I should generate a random URL,,,? – Dave Mar 16 '14 at 23:52
0

You can try:

NSString *theURL = [NSString stringWithFormat:@"%@?t=%@", url, [[NSProcessInfo processInfo] globallyUniqueString]];
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:theURL] cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:8.0]];
klcjr89
  • 5,862
  • 10
  • 58
  • 91