清除WKWebview的cookie

- (void)deleteWebCookiesCache:(NSString *)strUrl {
    
    if (@available(iOS 9.0, *)) {//iOS9及以上
        NSArray *types = @[WKWebsiteDataTypeCookies, WKWebsiteDataTypeSessionStorage];
        NSSet *websiteDataTypes = [NSSet setWithArray:types];
        NSDate *dateFromater = [NSDate dateWithTimeIntervalSince1970:0];
        [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:websiteDataTypes modifiedSince:dateFromater completionHandler:^{
            
        }];
    }else { //iOS9以下
         NSString *libraryPath = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) objectAtIndex:0];
            NSString *cookiesFolderPath = [libraryPath stringByAppendingString:@"/Cookies"];
            NSError *errors;
            [[NSFileManager defaultManager] removeItemAtPath:cookiesFolderPath error:&errors];
        }
   
}

你可能感兴趣的:(清除WKWebview的cookie)