在我的APP中,我们通过继承NSURLCache类并实现了将本地文件数据作为缓存数据传递所需的方法,为缓存创建了自定义类。I have done it same as this tutorial
在我的APP中有一个刷新按钮,点击它我必须刷新当前页面我已经完成以下加载本地存储的CSS和JS文件
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
if (isGoingToRefresh) {
[NSURLCache setSharedURLCache:cache];
isGoingToRefresh = NO;
return YES;
}
NSString *path = [mainWebView stringByEvaluatingJavaScriptFromString:@"window.location.pathname"];
path = [NSString stringWithFormat:@"%@%@",[[[AppDelegate sharedAppDelegate]configurationFile]objectForKey:@"RootURL"],path];
[NSURLCache setSharedURLCache:cache];
if ([path isEqualToString:[[request URL]absoluteString]]) {
[self showRefreshLoader];
isGoingToRefresh = YES;
NSURLRequest *localRequest = [NSURLRequest requestWithURL:[request URL] cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:240] ;
[webView loadRequest:localRequest];
return NO;
}
return YES;
}
上面的代码是通过调用NSURLCache方法 -
来从缓存加载数据- (NSCachedURLResponse *)cachedResponseForRequest:(NSURLRequest *)request
但是在iOS4上webView没有调用NSURLCache方法。
我不明白为什么请建议我一些好的解决方案。
答案 0 :(得分:0)
尝试使用您的请求
NSURLRequest *theRequest = [NSURLRequest requestWithURL:url
cachePolicy:NSURLCacheStorageAllowed
timeoutInterval:60];