how to clear webview cache in ipad

2019-06-11 05:07发布

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

2条回答
甜甜的少女心
2楼-- · 2019-06-11 05:35

Use -

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

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

[webView loadRequest:urlRequest];
查看更多
趁早两清
3楼-- · 2019-06-11 05:48

Easy way :

NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:0 diskCapacity:0 diskPath:nil];
[NSURLCache setSharedURLCache:sharedCache];
查看更多
登录 后发表回答