【问题标题】:Can't clear UIWebView cache无法清除 UIWebView 缓存
【发布时间】:2013-07-24 09:22:06
【问题描述】:

我似乎找不到清除 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
}

有人遇到过这个吗?谢谢!

【问题讨论】:

  • 你解决了吗?我也解决不了。

标签: ios caching uiwebview


【解决方案1】:

您似乎已经尝试了几乎所有方法。我知道你拒绝 cookie。然而,你为什么不试试这个?这对我有用...

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

【讨论】:

  • 不幸的是没有帮助。它仍然被缓存。
猜你喜欢
  • 2011-07-25
  • 2013-02-09
  • 2011-02-01
  • 2013-09-09
  • 2015-03-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多