【问题标题】:Clearing Caches from safari in iOS在 iOS 中从 Safari 中清除缓存
【发布时间】:2014-02-22 07:08:23
【问题描述】:

我有一个应用程序可以在 UIWebView 中从服务器加载 pdf 文件

当我从服务器更改 pdf 文件时,它不会在应用程序中更改,我尝试了所有这些方法

[[NSURLCache sharedURLCache] removeCachedResponseForRequest:request];

[[NSURLCache sharedURLCache] removeAllCachedResponses];

for(NSHTTPCookie *cookie in [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies]) {
    if([[cookie domain] isEqualToString:MyURLString]) {
        [[NSHTTPCookieStorage sharedHTTPCookieStorage] deleteCookie:cookie];
    }
}

新的pdf文件仍然没有改变,有时需要一些时间才能改变,有时它不会

还有其他方法吗?

【问题讨论】:

  • 我很想知道这个问题的答案。我们必须继承 NSURLProtocol 才能在 UIWebView 中清除缓存,因此了解是否有更简单的方法会很有用。
  • 你能解释一下如何继承NSURLProtocol,如果它和你一起工作吗? @达伦

标签: ios uiwebview browser-cache


【解决方案1】:

[[NSURLCache sharedURLCache] removeAllCachedResponses];[[NSURLCache sharedURLCache] removeAllCachedResponses]; 都不适合你,这很奇怪。

你可以再尝试一个(虽然不是很好)技巧:

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
    if(request.cachePolicy != NSURLRequestReloadIgnoringLocalCacheData) {
        NSURLRequst* noCacheRequest = [[NSURLRequest alloc] initWithURL:request.URL cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:request.timeoutInterval];
        [webView loadRequest:noCacheRequest];
        return false;
    }
    else
        return true;
}

另外,试试setHTTPShouldHandleCookies:,比如here

【讨论】:

  • 你能具体解释一下吗? ,尝试了 setHTTPShouldHandleCookies 仍然无法为我工作
  • 我已经用函数实现更新了评论。这不太好,我还没有尝试过,所以我尝试了一下,希望它会对你有所帮助。祝你好运!
  • 感谢您的帮助,文件正在链接,但仍需要一些时间来更改 :)
猜你喜欢
  • 1970-01-01
  • 2019-09-29
  • 1970-01-01
  • 2017-05-28
  • 1970-01-01
  • 1970-01-01
  • 2015-05-26
  • 2020-02-08
  • 1970-01-01
相关资源
最近更新 更多