2

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

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

4

1 回答 1

0

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

   NSHTTPCookie *aCookie;
    for (aCookie in [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies]) {
        [[NSHTTPCookieStorage sharedHTTPCookieStorage] deleteCookie:aCookie];
    }
于 2013-07-24T18:29:02.043 回答