【发布时间】:2018-08-17 23:14:58
【问题描述】:
我尝试了更多方法在 UIWebView 中加载请求,而不使用缓存数据。我必须从 url 加载 受保护的 pdf。不幸的是,任何尝试都没有成功。这是我的代码:
[mypdfView removeFromSuperview];
mypdfView = [[UIWebView alloc] initWithFrame:CGRectMake(0,85,self.view.frame.size.width,self.view.frame.size.height-150)];
mypdfView.backgroundColor = [UIColor clearColor];
mypdfView .autoresizesSubviews = YES;
mypdfView .autoresizingMask=(UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth);
NSString *urlstring = @"https://user:psw@mysites.com/mypdf.pdf";
NSURL *myUrl = [NSURL URLWithString:urlstring];
NSURLRequest *myRequest = [NSURLRequest requestWithURL:myUrl];
[mypdfView loadRequest:myRequest];
第一次尝试:忽略缓存数据的新请求
NSURLRequest *myRequest = [NSURLRequest requestWithURL:myUrl cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:20.0];
没有成功。 第二次尝试:清理 myRequest 缓存数据
[[NSURLCache sharedURLCache] removeCachedResponseForRequest:myRequest];
[[NSURLCache sharedURLCache] removeAllCachedResponses];
没办法。 3尝试:清除所有缓存并删除所有cookie
[[NSURLCache sharedURLCache]removeAllCachedResponses];
[[NSURLCache sharedURLCache] setDiskCapacity:0];
[[NSURLCache sharedURLCache] setMemoryCapacity:0];
for(NSHTTPCookie *cookie in [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies]) {
if([[cookie domain] isEqualToString:urlstring]) {
[[NSHTTPCookieStorage sharedHTTPCookieStorage] deleteCookie:cookie];
}
}
再次。没有成功。所以试图删除所有凭据:
NSURLCredentialStorage *credentialsStorage = [NSURLCredentialStorage sharedCredentialStorage];
NSDictionary *allCredentials = [credentialsStorage allCredentials];
for (NSURLProtectionSpace *protectionSpace in allCredentials) {
NSDictionary *credentials = [credentialsStorage credentialsForProtectionSpace:protectionSpace];
for (NSString *credentialKey in credentials) {
[credentialsStorage removeCredential:[credentials objectForKey:credentialKey] forProtectionSpace:protectionSpace];
}
}
再次失败。
有什么想法吗?
感谢您的帮助。
【问题讨论】:
-
你怎么知道文件正在从缓存中加载?
-
'因为我改变了它然后重新加载了 webview 而 webview 没有改变。
-
更多我从我的服务器中删除了它并且 webview 仍然显示它。
标签: ios objective-c caching uiwebview