iOS UI篇 - UIWebView缓存清除

来源:互联网 发布:mac搜狗输入罗马数字 编辑:程序博客网 时间:2024/06/05 20:16

使用iOS的webview会自动进行缓存,我们在开发的时候要记得清除Cookie和缓存。

在webview的关闭按钮中添加两个方法

/**webView退出方法*/  - (void)closeBtnAction:(UIButton *)button{       _webView = nil;      [self cleanCacheAndCookie];      [self.navigationController popViewControllerAnimated:YES];  }  
/**清除缓存和cookie*/  - (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];  }  
0 0
原创粉丝点击