如何在ipad中清除webview缓存

时间:2012-05-21 14:03:00

标签: objective-c ios ipad uiwebview

这里我使用

加载了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];

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

2 个答案:

答案 0 :(得分:2)

简单方法:

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

答案 1 :(得分:2)

使用 -

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

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

[webView loadRequest:urlRequest];