我创建了一个在iOS应用中离线运行的UIWebView
。我正在利用某个javascript库来显示虚拟游览,这就是我需要使用UIWebView
的原因。
我现在遇到运行应用程序的问题:很多时候它显示旧图像,即使它们不在资源中或已经更新。我已经尝试了很多方法来解决这个问题,包括设置缓存策略:
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"splash2" ofType:@"html"]isDirectory:NO];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData];
[self.webView loadRequest:request];
在viewDidLoad
的最顶部,我尝试设置缓存容量:
NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:0 diskCapacity:0 diskPath:nil];
[NSURLCache setSharedURLCache:sharedCache];
这在我的应用程序上有了FininLaunchingWithOptions:
[[NSURLCache sharedURLCache] removeAllCachedResponses];
目前我的viewDidLoad
NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:0 diskCapacity:0 diskPath:nil];
[NSURLCache setSharedURLCache:sharedCache];
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"splash2" ofType:@"html"]isDirectory:NO];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData];
[self.webView loadRequest:request];
webView.frame = CGRectMake(0, 0, 1024, 768);
webView.scalesPageToFit = NO;
webView.multipleTouchEnabled = YES;
for (id subview in webView.subviews)
if ([[subview class] isSubclassOfClass: [UIScrollView class]])
((UIScrollView *)subview).bounces = NO;
[super viewDidLoad];
我也试过viewDidLoad
:
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"splash2" ofType:@"html"]isDirectory:NO]];
webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)];
NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:0 diskCapacity:0 diskPath:nil];
[NSURLCache setSharedURLCache:sharedCache];
[webView loadRequest:request];
[self.view addSubview:webView];
webView.scalesPageToFit = NO;
webView.multipleTouchEnabled = YES;
for (id subview in webView.subviews)
if ([[subview class] isSubclassOfClass: [UIScrollView class]])
((UIScrollView *)subview).bounces = NO;
[super viewDidLoad];
此外,我不确定它是否与html5清单有关。总而言之,我只是需要它来关闭缓存并始终阅读我资源中当前存在的内容。