我需要在关闭WebView后清除缓存
我使用Xamarin iOS clear cache from WKWebView中的代码
但这没有效果。已经了解records.Count equals 0
如何使它正确?

var websiteDataTypes = new NSSet<NSString>(new []
{
    //Choose which ones you want to remove
    WKWebsiteDataType.Cookies,
    WKWebsiteDataType.DiskCache,
    WKWebsiteDataType.IndexedDBDatabases,
    WKWebsiteDataType.LocalStorage,
    WKWebsiteDataType.MemoryCache,
    WKWebsiteDataType.OfflineWebApplicationCache,
    WKWebsiteDataType.SessionStorage,
    WKWebsiteDataType.WebSQLDatabases
});

WKWebsiteDataStore.DefaultDataStore.FetchDataRecordsOfTypes (websiteDataTypes, (NSArray records) =>
{
    for (nuint i = 0; i < records.Count; i++) {
        var record = records.GetItem<WKWebsiteDataRecord> (i);

        WKWebsiteDataStore.DefaultDataStore.RemoveDataOfTypes (record.DataTypes,
            new[] {record}, () => {Console.Write($"deleted: {record.DisplayName}");});
    }
});

最佳答案

通过以下代码解决了问题:

NSHttpCookieStorage CookieStorage = NSHttpCookieStorage.SharedStorage;

        foreach (var cookie in CookieStorage.Cookies)
            CookieStorage.DeleteCookie(cookie);

10-08 06:26