Delete Web Cache / Javascript Storage

bswanbswan USMember ✭✭

I have an app that is using an http server to serve files to a Web View. The web viewers are caching image links which is causing broken images when their paths changes.

I can delete the web store on Android and UWP but I cannot figure out how to properly with iOS.

Android:

Android.Webkit.WebStorage.Instance.DeleteAllData();

UWP:

Windows.UI.Xaml.Controls.WebView.ClearTemporaryWebDataAsync();

I have tried the following with no luck:

        NSHttpCookieStorage.SharedStorage.RemoveCookiesSinceDate(NSDate.DistantPast);
        WKWebsiteDataStore.DefaultDataStore.FetchDataRecordsOfTypes(WKWebsiteDataStore.AllWebsiteDataTypes, (NSArray records) =>
        {
            for (nuint i = 0; i < records.Count; i++)
            {
                var record = records.GetItem<WKWebsiteDataRecord>(i);

                WKWebsiteDataStore.DefaultDataStore.RemoveDataOfTypes(
                    websiteDataTypes: record.DataTypes,
                    date: new[] { record },
                    completionHandler: () => { });
            }

            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}"); });
            }
        });

        NSUrlCache.SharedCache.RemoveAllCachedResponses();



        NSUrlCache.SharedCache.DiskCapacity = 0;
        NSUrlCache.SharedCache.MemoryCapacity = 0;

Best Answer

Answers

  • NMackayNMackay GBInsider, University mod

    @bswan

    Thanks for sharing.

Sign In or Register to comment.