Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Want to clear UIWebView cache from server side

I have created an HTML page. From my iPhone app I am using that URL in my UIWebView.

Here I want to set a code in my HTML, in which I can tell UIWebView not to use cache. Or I want to tell URL not to use cache.

If I am not able to explain you correctly, free to ask me.

like image 328
Helen voy Avatar asked Dec 05 '25 14:12

Helen voy


2 Answers

Clean the HTML document by removing all content

  [webview stringByEvaluatingJavaScriptFromString:@"document.body.innerHTML='';"];

Or Flush all cached data like bellow..

[[NSURLCache sharedURLCache] removeAllCachedResponses];

For more information see this blog UIWebView-secrets-part

like image 113
Paras Joshi Avatar answered Dec 07 '25 03:12

Paras Joshi


I assume you want to disable cache by looking at an info on html or url. I suggest you to place this info in HTML between unique tags. You could parse it using string operations after.

If you are using url you should use something like query string.

Finally disabling cache is done by

    [[NSURLCache sharedURLCache] removeAllCachedResponses];
    [[NSURLCache sharedURLCache] setDiskCapacity:0];
    [[NSURLCache sharedURLCache] setMemoryCapacity:0];

However this code disables cache for good. If you want to enable it again you should set disk capacity and memory capacity to a higher value.

like image 41
Can Leloğlu Avatar answered Dec 07 '25 04:12

Can Leloğlu