因为存在缓存策略,如果要实时加载最新网页,那么就需要清除缓存代码了,代码如下
- (void)deleteWebCache {
if([[UIDevicecurrentDevice].systemVersionfloatValue] >=9.0) {
NSSet*websiteDataTypes
= [NSSetsetWithArray:@[
WKWebsiteDataTypeDiskCache,
//WKWebsiteDataTypeOfflineWebApplicationCache,
WKWebsiteDataTypeMemoryCache,
//WKWebsiteDataTypeLocalStorage,
//WKWebsiteDataTypeCookies,
//WKWebsiteDataTypeSessionStorage,
//WKWebsiteDataTypeIndexedDBDatabases,
//WKWebsiteDataTypeWebSQLDatabases
]];
//// All kinds of data
//NSSet *websiteDataTypes = [WKWebsiteDataStore allWebsiteDataTypes];
//// Date from
NSDate*dateFrom = [NSDatedateWithTimeIntervalSince1970:0];
//// Execute
[[WKWebsiteDataStoredefaultDataStore]removeDataOfTypes:websiteDataTypesmodifiedSince:dateFromcompletionHandler:^{
// Done
}];
}else{
NSString*libraryPath = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,NSUserDomainMask,YES)objectAtIndex:0];
NSString*cookiesFolderPath = [libraryPathstringByAppendingString:@"/Cookies"];
NSError*errors;
[[NSFileManagerdefaultManager]removeItemAtPath:cookiesFolderPatherror:&errors];
}
}