在UIWebView下,可以使用
[[NSURLCache sharedURLCache] removeAllCachedResponses];//清除缓存
WKWebView清除COOKIEs的方法(iOS9以上)
WKWebsiteDataStore *dateStore = [WKWebsiteDataStore defaultDataStore]; [dateStore fetchDataRecordsOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] completionHandler:^(NSArray* __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的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。