如果项目中使用了wkwebview,只用[[NSHTTPCookieStorage sharedHTTPCookieStorage] delete:cookie]
是不行的,要用[[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:]
+(void)clearCookie {
// allWebsiteDataTypes清除所有缓存
NSArray * types = @[WKWebsiteDataTypeCookies];
NSSet*websiteDataTypes= [NSSetsetWithArray:types];
NSDate *dateFrom = [NSDate dateWithTimeIntervalSince1970:0];
[[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:websiteDataTypes modifiedSince:dateFrom completionHandler:^{
}];
//清除cookies
NSHTTPCookie*cookie;
NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for(cookiein[storagecookies]){
[storagedeleteCookie:cookie];
}
}
网友评论