0

Here i have load the content in the uiwebview using

[webView loadHTMLString:[theApp.contentArr objectAtIndex:spineIndex] baseURL:url];

after going back and come i need to clear the cache

here i have tried these kinds of methods to clear the cache:

 [webView stringByEvaluatingJavaScriptFromString:@"document.body.innerHTML = \"\";"];
    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"about:blank"]]];
    // remove all cached responses
        [[NSURLCache sharedURLCache] removeAllCachedResponses];

        // set an empty cache
    NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:0 diskCapacity:0 diskPath:nil];
    [NSURLCache setSharedURLCache:sharedCache];

but no use, what is the solution for this.....

dineshprasanna
  • 1,284
  • 4
  • 20
  • 37

2 Answers2

2

Easy way :

NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:0 diskCapacity:0 diskPath:nil];
[NSURLCache setSharedURLCache:sharedCache];
Damien Locque
  • 1,810
  • 2
  • 20
  • 42
2

Use -

[webView stringByEvaluatingJavaScriptFromString:@"document.body.innerHTML = \"\";"];

NSURLRequest *urlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:@"about:blank"]];
[urlRequest setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData];

[webView loadRequest:urlRequest];
rishi
  • 11,779
  • 4
  • 40
  • 59
  • it get crashed i the following line [urlRequest setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData]; saying "NsUrlreqest may not respond to setcachepolicy" – dineshprasanna May 21 '12 at 14:24
  • 1
    sorry use NSMutableURLRequest instead of NSURLRequest. – rishi May 21 '12 at 14:27
  • thanx for ur help, its working but only for the first time alone. When loading again and again the cache is not removed...how to clear this... – dineshprasanna May 22 '12 at 05:27