clear the Wkwebview cache
OC notation: Swift is written again below.
Clear the Wkwebview cache so that the H5 page updates to the latest page as soon as it refreshes
Directly on the code! ~~
To differentiate between iOS9.0 and 8.0
-(void) Deletewebcache {
if ([[Uidevice currentdevice].systemversion Floatvalue] >= 9.0) {
Nsset *websitedatatypes
= [Nsset setwitharray:@[
Wkwebsitedatatypediskcache,
Wkwebsitedatatypeofflinewebapplicationcache,
Wkwebsitedatatypememorycache,
Wkwebsitedatatypelocalstorage,
Wkwebsitedatatypecookies,
Wkwebsitedatatypesessionstorage,
Wkwebsitedatatypeindexeddbdatabases,
Wkwebsitedatatypewebsqldatabases
]];
All kinds of data
Nsset *websitedatatypes = [Wkwebsitedatastore allwebsitedatatypes];
Date from
NSDate *datefrom = [NSDate datewithtimeintervalsince1970:0];
Execute
[[Wkwebsitedatastore Defaultdatastore] Removedataoftypes:websitedatatypes modifiedsince:datefrom CompletionHandler :^{
Done
}];
} else {
NSString *librarypath = [Nssearchpathfordirectoriesindomains (nslibrarydirectory, Nsuserdomainmask, YES) OBJECTATINDEX:0];
NSString *cookiesfolderpath = [LibraryPath stringbyappendingstring:@ "/cookies"];
Nserror *errors;
[[Nsfilemanager Defaultmanager] Removeitematpath:cookiesfolderpath error:&errors];
}
}
Swift
MARK:- Empty the cache
func ClearCache () {
let datefrom: nsdate = nsdate. Init(timeIntervalSince1970: 0)
if #available(iOS 9.0, *) {
let websitedatatypes: nsset = wkwebsitedatastore. Allwebsitedatatypes()
Wkwebsitedatastore. Defaultdatastore(). Removedataoftypes(websitedatatypes as!) Set<String;, modifiedsince:datefrom) {
Print(" empty cache complete ")
}
} Else {
let librarypath = nssearchpathfordirectoriesindomains(. Librarydirectory,. Userdomainmask, true) [0]
let cookiesfolderpath = LibraryPath. Stringbyappendingstring("/cookies")
Let errors: nserror
try? Nsfilemanager. Defaultmanager(). removeItemAtPath(cookiesfolderpath)
}
}
Clear the Wkwebview cache