2013-07-24 101 views
2

我似乎無法找到清除UIWebView緩存的方法。我已經嘗試了以下,但沒有工作到目前爲止:無法清除UIWebView緩存

[[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyNever]; 

[[NSURLCache sharedURLCache] removeCachedResponseForRequest:_request]; 
[[NSURLCache sharedURLCache] removeAllCachedResponses]; 
_request = nil; 

[NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:0 diskCapacity:0 diskPath:nil]; 
[NSURLCache setSharedURLCache:sharedCache]; 

_request = [NSMutableURLRequest requestWithURL:t_url 
      cachePolicy:NSURLRequestReloadIgnoringLocalCacheData 
// also tried NSURLRequestReloadIgnoringLocalAndRemoteCacheData and NSURLRequestReloadIgnoringCacheData 
      timeoutInterval:10.0]; 
[_request setCachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData]; 
[_request setHTTPShouldHandleCookies:NO]; 

- (NSCachedURLResponse *)connection:(NSURLConnection *)connection 
        willCacheResponse:(NSCachedURLResponse *)cachedResponse { 
    return nil; // Actually never gets called 
} 

有人遇到過這個?謝謝!

+0

你解決了嗎?我也無法解決這個問題。 – Curnelious

回答

0

你似乎已經嘗試了幾乎所有的東西。我知道你正在拒絕Cookie。然而,你爲什麼不試試這個?這對我工作...

NSHTTPCookie *aCookie; 
    for (aCookie in [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies]) { 
     [[NSHTTPCookieStorage sharedHTTPCookieStorage] deleteCookie:aCookie]; 
    } 
+0

不幸的是沒有幫助。它仍然被緩存。 – Django