删除cache文件夹是最好的清空缓存的方式:
- (void)clearAllUIWebViewData {
// Clear the webview cache...
[[NSURLCache sharedURLCache] removeAllCachedResponses];
[self removeApplicationLibraryDirectoryWithDirectory:@"Caches"];
[self removeApplicationLibraryDirectoryWithDirectory:@"WebKit"];
// Empty the cookie jar...
for (NSHTTPCookie *cookie in [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies]) {
[[NSHTTPCookieStorage sharedHTTPCookieStorage] deleteCookie:cookie];
}
[selfremoveApplicationLibraryDirectoryWithDirectory:@"Cookies"];
}
- (void)removeApplicationLibraryDirectoryWithDirectory:(NSString *)dirName {
NSString *dir = [[[[NSSearchPathForDirectoriesInDomains(NSApplicationDirectory, NSUserDomainMask, YES) lastObject]stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"Library"] stringByAppendingPathComponent:dirName];
if ([[NSFileManager defaultManager] fileExistsAtPath:dir]) {
[[NSFileManager defaultManager] removeItemAtPath:dir error:nil];
}
}
网友评论