一. UIWebView-清楚緩存
- 在使用WKWebView之前使用的是UIWebView, 清除緩存的方式兩種:
- NSURLCache 和 NSHTTPCookieStorage 對(duì)象的清除方式
NSHTTPCookie *cookie;
NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (cookie in [storage cookies]) {
[storage deleteCookie:cookie];
}
NSURLCache *cache = [NSURLCache sharedURLCache];
[cache removeAllCachedResponses];
[cache setMemoryCapacity:0];
[cache setDiskCapacity:0];
- NSURLRequest對(duì)象的不緩存機(jī)制:NSURLRequestReloadIgnoringCacheData
//NSURLRequest *urlRequest = [NSURLRequest requestWithURL:_url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:15.0];
//[self.web_view loadRequest:urlRequest];
[self.web_view loadRequest:[NSURLRequest requestWithURL:_url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30.0]];
二. WKWebView清除緩存
ios8 問世之后, 本作者立馬想換掉老的UIWebView, WKWebView的好處這里就不介紹了. 由于項(xiàng)目已成型了且諸多JS交互, 與web人員溝通了一陣, 終于同意使用新控件.
上面的
(1) NSURLCache 和 NSHTTPCookieStorage 對(duì)象的清除方式
對(duì)WKWebView沒起到作用. 采用方式NSURLRequest對(duì)象的不緩存機(jī)制:NSURLRequestReloadIgnoringCacheData
[self.web_view loadRequest:[NSURLRequest requestWithURL:_url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30.0]];