UIWebView Cache in iOS

I host a UIWebView in my application. it looks like a UIWebView , caches images and data. I want to clear the cache when the application starts.

Clearing the Safari cache does not help. the only way I found the UIWebView cache reset was to turn off the iPhone and turn it back on. Closing the application also does not help.

Apple's documentation says nothing about this ... or something is missing for me. Just in case, the application is created using monotone.

+2
source share
3 answers

If you want to destroy all cached responses, something like this looks like a way:

 [[NSURLCache sharedURLCache] removeAllCachedResponses]; 
+1
source

There is a viewing cache that shows a bitmap of the last page used (for example, we see inside Safari), but this does not look like what you see (since a reboot is required to reboot the device).

I have not noticed this behavior before (I never looked for it;), but the following answer looks promising.

FWIW is not something that would be typical of MonoTouch.

0
source

Ive tried all the stack overflow suggestions and none of them work. The only way to make it work and feel that its reliable solution is to create new html files in the temp directory (with a different directory name - Guid works best) every time and copy all the related images, scripts, css, each time to this temp directory.

Then open it using the NSUrlRequest object

 string tempdir = Path.Combine(UIController.Common.DataFolder,System.Guid.NewGuid().ToString ()); Directory.CreateDirectory (tempdir); //-- create your html on the tempdirectory here //-- copy all the images, and all the css, and js files UIWebView wv = new UIWebView(new RectangleF(30,30,480,680)); NSUrlRequest req = new NSUrlRequest(new NSUrl (Path.Combine (tempdir,"default.html"), false),NSUrlRequestCachePolicy.ReloadRevalidatingCacheData,10); wv.LoadFinished += delegate(object sender1, EventArgs e1) { //delete the tempdirectory Directory.Delete(tempdir); }; 
0
source

All Articles