如何清除在ipad网页流量缓存(how to clear webview cache in ipad

2019-09-17 09:16发布

在这里,我用在UIWebView的内容加载

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

回去后,和前来我需要清除缓存

在这里,我尝试了这些种方法清除缓存:

 [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];

但是没有用,什么是该解决方案.....

Answer 1:

简单的方法 :

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


Answer 2:

采用 -

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

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

[webView loadRequest:urlRequest];


文章来源: how to clear webview cache in ipad