美文网首页
WebView加载url不更新 清除缓存 iOS开发

WebView加载url不更新 清除缓存 iOS开发

作者: 想飞的菜鸟 | 来源:发表于2017-10-20 14:33 被阅读0次

后台更新了URL的内容之后,在没有删除app的情况下直接进行了安装,导致出现了网页内容不更新的情况,在删除了原来的APP,重新打包之后,情况恢复,怀疑是自己写的webview没有添加清除缓存功能造成,下面是清除缓存的代码:

- (void)leftBarButtonAction : (UIBarButtonItem *)sender {
    [self.baseButton removeFromSuperview];
    _baseWebView = nil;
    [self cleanCacheAndCookie];
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)cleanCacheAndCookie{
    //清除cookies
    NSHTTPCookie *cookie;
    NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
    for (cookie in [storage cookies]){
        [storage deleteCookie:cookie];
    }
    //清除UIWebView的缓存
    [[NSURLCache sharedURLCache] removeAllCachedResponses];
    NSURLCache * cache = [NSURLCache sharedURLCache];
    [cache removeAllCachedResponses];
    [cache setDiskCapacity:0];
    [cache setMemoryCapacity:0];
} 

或者加载的时候直接禁止缓存

request = [NSURLRequest requestWithURL:url  cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:10];

相关文章

网友评论

      本文标题:WebView加载url不更新 清除缓存 iOS开发

      本文链接:https://www.haomeiwen.com/subject/ijhvuxtx.html