dineshprasanna
dineshprasanna

Reputation: 1284

how to clear webview cache in ipad

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.....

Upvotes: 0

Views: 3216

Answers (2)

rishi
rishi

Reputation: 11839

Use -

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

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

[webView loadRequest:urlRequest];

Upvotes: 2

Damien Locque
Damien Locque

Reputation: 1809

Easy way :

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

Upvotes: 2

Related Questions