我有一个应用程序,可以从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文件仍然没有改变,有时需要一些时间来改变,有时它不会
还有其他方法吗?
答案 0 :(得分: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