使用iOS的UIWebview會自動進行緩存,我們在開發的時候要記得清除Cookie和緩存。
_webView = nil;
[self cleanCacheAndCookie];
調用的方法代碼如下:
/**清除緩存和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];
}