IOS: force UIWebView to reload / prevent caching

I have an iPhone app that displays a website. This website changes content from time to time, but my application does not reload it every time it is open. I tried to prevent site caching, but to no avail.

This is my init method:

- (id)init:(NSString *)url withTitle:(NSString *)theTitle withPageName:(NSString *)pageName { self = [super init]; if(self) { NSLog(@"websiteviewcontroller init"); self.title = theTitle; self.url = url; self.pageName = pageName; CGRect frame = [[UIScreen mainScreen] applicationFrame]; webView = [[UIWebView alloc] initWithFrame:frame]; NSURL *theURL = [NSURL URLWithString:url]; [webView loadRequest:[NSURLRequest requestWithURL:theURL]]; // support zooming webView.scalesPageToFit = YES; //[[NSURLCache sharedURLCache] removeAllCachedResponses]; [webView reload]; } return self; } 

This is my viewWillAppear method:

 - (void)viewWillAppear:(BOOL)animated { CGRect frame = [[UIScreen mainScreen] applicationFrame]; webView = [[UIWebView alloc] initWithFrame:frame]; NSURL *theURL = [NSURL URLWithString:url]; [webView loadRequest:[NSURLRequest requestWithURL:theURL]]; [webView reload]; // support zooming webView.scalesPageToFit = YES; } 

Please help me solve this problem. All answers are greatly appreciated.

+6
source share
2 answers

This snipplet code fixed my problem:

 [[NSURLCache sharedURLCache] removeAllCachedResponses]; 
+10
source

The answer to the following question. For a complete answer to ore: UIwebview without cache

0
source

Source: https://habr.com/ru/post/917690/


All Articles