Delete all WKWebView and URLSession related cached data

53 Views Asked by At

I use WKWebView to authenticate on a site, copy the downloaded cookies to an array and use them with a subsequent URLSession. This is to avoid authentications on every request. All works fine, but my app (>= iOS 14) also has a feature to reset the settings, which should force a new authentication.

HTTPCookieStorage.shared.cookies?.forEach(HTTPCookieStorage.shared.deleteCookie)
WKWebsiteDataStore.default().removeData(ofTypes: WKWebsiteDataStore.allWebsiteDataTypes(),
                                                 modifiedSince: Date.distantPast,
                                                 completionHandler: {})
URLCache.shared.removeAllCachedResponses()

After above reset is done, the URL request still works without authentication. Hence some data is still cached somewhere.

What do I miss?

0

There are 0 best solutions below