iOS清除WKWebView缓存
作者:互联网
//清除缓存
[[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 data records to delete website data for.
@param completionHandler A block to invoke when the website data for the records has been removed.
*/
- (void)removeDataOfTypes:(NSSet<NSString *> *)dataTypes forDataRecords:(NSArray<WKWebsiteDataRecord *> *)dataRecords completionHandler:(void (^)(void))completionHandler;
/*! @abstract Removes all website data of the given types that has been modified since the given date.
@param dataTypes The website data types that should be removed.
@param date A date. All website data modified after this date will be removed.
@param completionHandler A block to invoke when the website data has been removed.
*/
- (void)removeDataOfTypes:(NSSet<NSString *> *)dataTypes modifiedSince:(NSDate *)date completionHandler:(void (^)(void))completionHandler;
标签:website,缓存,void,completionHandler,iOS,param,date,data,WKWebView 来源: https://blog.csdn.net/watson2017/article/details/120978164