Open ChrisRockC opened 6 years ago
if ([[[UIDevicecurrentDevice]systemVersion]intValue ] >8) { NSArray types =@[WKWebsiteDataTypeMemoryCache,WKWebsiteDataTypeDiskCache]; // 9.0之后才有的 NSSet websiteDataTypes = [NSSetsetWithArray:types]; NSDate *dateFrom = [NSDatedateWithTimeIntervalSince1970:0];
[[WKWebsiteDataStoredefaultDataStore]removeDataOfTypes:websiteDataTypesmodifiedSince:dateFromcompletionHandler:^{ }];
}else{ NSString *libraryPath = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,NSUserDomainMask,YES) objectAtIndex:0];
NSString *cookiesFolderPath = [libraryPathstringByAppendingString:@"/Cookies"]; NSLog(@"%@", cookiesFolderPath); NSError *errors; [[NSFileManagerdefaultManager]removeItemAtPath:cookiesFolderPatherror:&errors];
}
使用UIWebView加载页面的时候最理想的情况是:资源文件没有更新,就只加载缓存文件,如果有更新就第一时间使用新的文件。
我们可以使用一个类来实现,这个类也是我在网上找的,类名:
JWNetAutoCache,大家也可以点进去看这个类实现该效果的一个思路。
if ([[[UIDevicecurrentDevice]systemVersion]intValue ] >8) { NSArray types =@[WKWebsiteDataTypeMemoryCache,WKWebsiteDataTypeDiskCache]; // 9.0之后才有的 NSSet websiteDataTypes = [NSSetsetWithArray:types]; NSDate *dateFrom = [NSDatedateWithTimeIntervalSince1970:0];
}else{ NSString *libraryPath = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,NSUserDomainMask,YES) objectAtIndex:0];
}