Rashedul Alam
Rashedul Alam

Reputation: 27

Is there any way to clear cache from web view in Xamarin ios?

I have developed a hybrid xamarin ios mobile application using embedio(external package). I have added the front end resource files(html and javascript files) under ios project resources. Then we are running the static file server by using embedio in resources folder. And the web view is loading content from embedded server.

I have also implemented the in app update from inside the app. We are updating our app by opening external url from the app. For example: itms-services://?action=download-manifest;url=https://demo-application/download/1.0.1/plist

The ios is then starts updating as both app bundle id and the update plist bundle id is same.

The issue is the web view html content is not updated.

But if I the directly install the latest version, then the web view loads the updated content.

I have tired to change the location of static file server from the bundle resource to Environment.SpecialFolder.Personal and i have added version specific html content in resources folder. Also tried by clearing the cookies of the web view.

//embedded server

var staticFilesWebServer = new WebServer(XamarinConstants.XamarinConstants.FrontEndServerUrl);
                staticFilesWebServer.RegisterModule(new StaticFilesModule(location));
                staticFilesWebServer.Module<StaticFilesModule>().UseRamCache = true;
                staticFilesWebServer.Module<StaticFilesModule>().DefaultExtension = ".html";
                staticFilesWebServer.Module<StaticFilesModule>().UseGzip = false;

// main page where i have the web view 
WebView.BaseUrl = XamarinConstants.XamarinConstants.FrontEndServerUrl;
WebView.Source = XamarinConstants.XamarinConstants.FrontEndServerUrl + url;
//url for deepli`enter code here`nk 
WebView.ContentType = WebViewContentType.Internet;

web view should load the updated html content.

Upvotes: 2

Views: 3390

Answers (1)

foyss
foyss

Reputation: 983

This should do the trick for you:

NSHttpCookieStorage CookieStorage = NSHttpCookieStorage.SharedStorage;

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

Link provides more information here

Upvotes: 1

Related Questions