Remove UIWebView's internal cache

前端 未结 2 1079
执念已碎
执念已碎 2020-12-09 18:06

I\'m showing a web app in an UIWebView, and sometimes the content of pages will change. After content have been changed the app clears the cache. But when I go

相关标签:
2条回答
  • 2020-12-09 18:46

    It appears that what's happening here is that it reloads the actual HTML file, but does not necessarily reload the resources within that page.

    A possible solution I've seen is to append a query parameter on to the end of the URL. For example:

    NSString *testURL = [NSString stringWithFormat:@"%@?t=%@", url, randQuery];
    [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:testURL] cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:10.0]];
    

    where you generate a random alphanumeric string as your randQuery query parameter, or keep a persistent count and just count up.

    This should force the UIWebView to load from the remote resource.

    0 讨论(0)
  • 2020-12-09 19:04

    I had the same issue and setting HTTPShouldHandleCookies property to NO fixed my problem.

    For example:

    NSMutableURLRequest  *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:strurl]];
    
    [request setHTTPShouldHandleCookies:NO];
    
    [webView loadRequest: request];
    

    Hope this help.

    0 讨论(0)
提交回复
热议问题