Skip to content

Instantly share code, notes, and snippets.

@insidegui
Created September 14, 2016 23:12
Show Gist options
  • Star 79 You must be signed in to star a gist
  • Fork 9 You must be signed in to fork a gist
  • Save insidegui/4a5de215a920885e0f36294d51263a15 to your computer and use it in GitHub Desktop.
Save insidegui/4a5de215a920885e0f36294d51263a15 to your computer and use it in GitHub Desktop.
Clear WKWebView's cookies and website data storage, very useful during development.
import Foundation
import WebKit
final class WebCacheCleaner {
class func clean() {
HTTPCookieStorage.shared.removeCookies(since: Date.distantPast)
print("[WebCacheCleaner] All cookies deleted")
WKWebsiteDataStore.default().fetchDataRecords(ofTypes: WKWebsiteDataStore.allWebsiteDataTypes()) { records in
records.forEach { record in
WKWebsiteDataStore.default().removeData(ofTypes: record.dataTypes, for: [record], completionHandler: {})
print("[WebCacheCleaner] Record \(record) deleted")
}
}
}
}
@JigneshVadadoriyaTR
Copy link

Thank you very much

@KovtunOleg
Copy link

Thanks man!

@shravanteegala
Copy link

Team,
Where we find all WebKit data in our IOS App storage ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment