无法清除UIWebView缓存

问题描述 投票:2回答:1

我似乎找不到清除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个回答
0
投票

你似乎已经尝试了几乎所有的方法。我知道你拒绝接受Cookie。但是,你为什么不试试这个呢?这个对我很有效...

   NSHTTPCookie *aCookie;
    for (aCookie in [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies]) {
        [[NSHTTPCookieStorage sharedHTTPCookieStorage] deleteCookie:aCookie];
    }
© www.soinside.com 2019 - 2024. All rights reserved.