清除WKWebView cookies的方法
程序员文章站
2023-12-20 08:03:09
在uiwebview下,可以使用
[[nsurlcache sharedurlcache] removeallcachedresponses];//清除缓存
wkwe...
在uiwebview下,可以使用
[[nsurlcache sharedurlcache] removeallcachedresponses];//清除缓存
wkwebview清除cookies的方法(ios9以上)
wkwebsitedatastore *datestore = [wkwebsitedatastore defaultdatastore]; [datestore fetchdatarecordsoftypes:[wkwebsitedatastore allwebsitedatatypes] completionhandler:^(nsarray<wkwebsitedatarecord *> * __nonnull records) { for (wkwebsitedatarecord *record in records) { // if ( [record.displayname containsstring:@"baidu"]) //取消备注,可以针对某域名清除,否则是全清 // { [[wkwebsitedatastore defaultdatastore] removedataoftypes:record.datatypes fordatarecords:@[record] completionhandler:^{ nslog(@"cookies for %@ deleted successfully",record.displayname); }]; // } } }];
ios9一下用这种方法:
nsstring *librarypath = [nssearchpathfordirectoriesindomains(nslibrarydirectory, nsuserdomainmask, yes) objectatindex:0]; nsstring *cookiesfolderpath = [librarypath stringbyappendingstring:@"/cookies"]; nserror *errors; [[nsfilemanager defaultmanager] removeitematpath:cookiesfolderpath error:&errors];
查看cookie
nshttpcookie *cookie; nshttpcookiestorage *cookiejar = [nshttpcookiestorage sharedhttpcookiestorage]; for (cookie in [cookiejar cookies]) { nslog(@"%@", cookie); }
以上这篇清除wkwebview cookies的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。