Clear the Wkwebview cache

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.