Xamarin iOS 从 WKWebView 清除缓存
Xamarin iOS clear cache from WKWebView
我正在执行以下操作以清除 WkWebView
中的缓存。我想知道如何确认缓存被清除
var request = new NSUrlRequest (webURL, NSUrlRequestCachePolicy.ReloadIgnoringLocalAndRemoteCacheData, 0);
NSUrlCache.SharedCache.RemoveAllCachedResponses ();
NSUrlCache.SharedCache.MemoryCapacity = 0;
NSUrlCache.SharedCache.DiskCapacity = 0;
有没有办法在发出请求时打印缓存
从这个 question 看来,您为 iOS 9 执行了此操作(c# 版本),它会打印出删除了哪些记录:
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}");});
}
});
或者对于 iOS 8,从 ShingoFukuyama/WKWebViewTips 您可以检查 Library 目录中的子目录 Cookies、Caches、WebKit 是否已删除。
iOS 8
After much trial and error, I've reached the following conclusion:
Use NSURLCache and NSHTTPCookie to delete cookies and caches in the same way as you used to do on UIWebView.
If you use WKProccessPool, re-initialize it.
Delete Cookies, Caches, WebKit subdirectories in the Library directory.
Delete all WKWebViews
我正在执行以下操作以清除 WkWebView
中的缓存。我想知道如何确认缓存被清除
var request = new NSUrlRequest (webURL, NSUrlRequestCachePolicy.ReloadIgnoringLocalAndRemoteCacheData, 0);
NSUrlCache.SharedCache.RemoveAllCachedResponses ();
NSUrlCache.SharedCache.MemoryCapacity = 0;
NSUrlCache.SharedCache.DiskCapacity = 0;
有没有办法在发出请求时打印缓存
从这个 question 看来,您为 iOS 9 执行了此操作(c# 版本),它会打印出删除了哪些记录:
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}");});
}
});
或者对于 iOS 8,从 ShingoFukuyama/WKWebViewTips 您可以检查 Library 目录中的子目录 Cookies、Caches、WebKit 是否已删除。
iOS 8
After much trial and error, I've reached the following conclusion:
Use NSURLCache and NSHTTPCookie to delete cookies and caches in the same way as you used to do on UIWebView.
If you use WKProccessPool, re-initialize it.
Delete Cookies, Caches, WebKit subdirectories in the Library directory.
Delete all WKWebViews