清除WKWebView cookies的方法
更新時間:2017年04月28日 10:35:53 投稿:jingxian
下面小編就為大家?guī)硪黄宄齏KWebView cookies的方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
在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的方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
iOS中Swift UISearchController仿微信搜索框
這篇文章主要介紹了iOS中Swift UISearchController仿微信搜索框效果,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2017-05-05iOS如何用100行代碼實(shí)現(xiàn)簡單的抽屜效果
最近在網(wǎng)上看到一些抽屜效果,看起來很酷!很眩!但是,下不下來看代碼, 所以決定還是自己寫吧!!這篇文章通過近100行的代碼就實(shí)現(xiàn)了簡單的抽屜效果,有需要的朋友們可以參考借鑒,下面來一起看看吧。2016-10-10使用Swift代碼實(shí)現(xiàn)iOS手勢解鎖、指紋解鎖實(shí)例詳解
這篇文章主要介紹了使用Swift代碼實(shí)現(xiàn)iOS手勢解鎖、指紋解鎖的實(shí)現(xiàn)過程,非常不錯具有參考借鑒價值,感興趣的朋友一起看看吧2016-06-06