1

情况: 一个原生IOS5 App从FTP下载一个网站到本地存储,一个webview显示下载的页面。如果 FTP-Server 上有新版本,App 会自动下载新版本并覆盖本地存储中的旧版本。现在 webview 应该加载新版本。

问题: 当新版本覆盖旧版本时,一些图像的名称会相同。现在 webview 将从文件系统的缓存中加载每个图像。-.-

问题: 是否有可能阻止 webview 从缓存中加载所有图像或清除整个缓存?我不能做的是更改下载页面的html或js。因此,无法在每张图片后面添加时间戳(test.img?timestamp=23444)。更改必须在 IOS 应用程序中完成。

我已经尝试过但失败了:

[[NSURLCache sharedURLCache] removeAllCachedResponses];

NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:0 diskCapacity:0 diskPath:nil];
[NSURLCache setSharedURLCache:sharedCache];

NSURL *url = [NSURL fileURLWithPath:[ftpPath stringByAppendingPathComponent:@"index.html"]];

NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:1.0];
[[NSURLCache sharedURLCache] removeCachedResponseForRequest: urlRequest];

[webView stopLoading];
[webView loadRequest:urlRequest];
[webView reload];
webView.delegate = self;

非常感谢您的帮助,我不明白。

西娅·南多

4

0 回答 0