//清除缓存
[[NSURLCache sharedURLCache] removeAllCachedResponses];
[[NSURLCache sharedURLCache] setDiskCapacity:0];
[[NSURLCache sharedURLCache] setMemoryCapacity:0];
//清除Cookie
NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (NSHTTPCookie *cookie in [storage cookies]) {
[storage deleteCookie:cookie];
}
iOS9之后新增了按时间清除web缓存的方法
NSSet *websiteDataTypes = [WKWebsiteDataStore allWebsiteDataTypes];
NSDate *dateFrom = [NSDate dateWithTimeIntervalSince1970:0];
[[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:websiteDataTypes modifiedSince:dateFrom completionHandler:^{
NSLog(@"WKWebsiteDataStore removeDataOfTypes");
}];
/*! @abstract Removes website data of the given types for the given data records.
@param dataTypes The website data types that should be removed.
@param dataRecords The website da

本文介绍了在iOS9及以上版本中,如何使用WKWebsiteDataStore API清除Web缓存,包括按类型和时间清除数据的详细步骤。同时涵盖了清除传统NSURLCache和HTTPCookie的方法。
最低0.47元/天 解锁文章
2126

被折叠的 条评论
为什么被折叠?



