你如何清除UIWebView的缓存?

JTA*_*pps 6 iphone cocoa-touch uiwebview ios

基本上,我需要知道如何在终止应用程序时使UIWebView擦除所有内容.基本上,它包括webView通过使用持有的所有cookie和信息.

有没有办法简单地清除它,以便它每次都像新的一样?

Jan*_*ano 6

UIWebView不缓存,它是NSURLConnection它使用的.以下任何一种情况都可以使用,并遵循以下文档NSURLCache:

// remove all cached responses
[[NSURLCache sharedURLCache] removeAllCachedResponses];

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

// remove the cache for a particular request
[[NSURLCache sharedURLCache] removeCachedResponseForRequest:request];
Run Code Online (Sandbox Code Playgroud)

但我不确定它现在是否存在(iOS 5).其他选项使用自定义缓存:SDURLCache覆盖连接:withCacheResponse : . 如果您发现当前的行为,请发表评论.