0
嘿傢伙在我的APP我已經創建了緩存的自定義類,通過繼承NSURLCache類和實現所需的方法來傳遞我的本地文件數據作爲緩存數據。 I have done it same as this tutorial爲什麼UIWebView無法從iOS4的緩存中加載數據?
在我的應用程序有一個刷新按鈕,在它的點擊我已經刷新當前頁面爲了這個,我已經做了以下加載本地存儲的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的web視圖沒有要求上述NSURLCache滿足HOD。
我不明白爲什麼請建議我一些很好的解決方案。
它是同以前的解決方案(無論我做了)......,我想它不工作的感謝答覆... – mithilesh 2012-04-27 14:25:29
這是一個不同的緩存策略。 – 2012-04-27 14:31:51
是否適用於不同的緩存策略? – 2012-04-27 18:41:13