Ios 脱机UIWebView查看旧图像
我创建了一个在iOS应用程序中离线运行的Ios 脱机UIWebView查看旧图像,ios,objective-c,image,caching,uiwebview,Ios,Objective C,Image,Caching,Uiwebview,我创建了一个在iOS应用程序中离线运行的UIWebView。我正在利用某个javascript库来显示虚拟游览,这就是为什么我需要使用UIWebView 我现在在运行应用程序时遇到了一个问题:大部分时间它都在显示旧图像,即使它们不在资源中或已更新。我尝试了很多方法来解决这个问题,包括设置缓存策略: NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"splash2" ofType:@"html"
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];
在我的应用程序中,它使用以下选项完成启动:
[[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清单有关。总之,我只想让它关闭缓存,并始终读取我资源中当前存在的内容。这是一个相当模糊的解释。。。