我在一个字符串中缓存UIWebView的HTML内容并尝试在应用程序离线时加载
if ([hostReach hostConnectionStatus] == NotReachable) { NSString *cachedResponse = [[NSString alloc] initWithData:[self responseHTMLData] encoding:NSNEXTSTEPStringEncoding]; [webView loadHTMLString:cachedResponse baseURL:final_url]; }
cachedResponse是一个HTML数据,但问题是UIWebView无法加载此数据
// WebView Delegate - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType { return YES; } - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error { // error description "connection is offline" }
如何在离线
时在UIWebVIew中加载HTML内容答案 0 :(得分:2)
HTML文件中引用的所有资源也必须进行缓存,baseURL
必须是这些缓存资源的路径。
答案 1 :(得分:-1)
NSString *pathLogo = @"Your Directory Path";
NSURL *baseURL_Logo = [NSURL fileURLWithPath:pathDir];
NSMutableString *contentHTML = [[NSMutableString alloc] init];
[contentHTML appendFormat:@"<img src=\"%@Image.png\"/>\n",baseURL_Logo];