0
votes

I am caching HTML contents of UIWebView in a string and trying it to load back when application is offline


 if ([hostReach hostConnectionStatus] == NotReachable) {
        NSString *cachedResponse = [[NSString alloc] initWithData:[self responseHTMLData] encoding:NSNEXTSTEPStringEncoding];
        [webView loadHTMLString:cachedResponse baseURL:final_url];

    }

cachedResponse is an HTML data in it but the problem is UIWebView fails to load this data

// 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"
}

How to I load HTML contents in UIWebVIew when its offline

2
What is the value of final_url. All resources referenced in the HTML file must be cached as well, and final_url needs to be a path to those cached resources.user3386109
@user3386109 that did worked. thanks .you add that as an ans and I can accept it.Kunal Balani
Glad to hear that worked for youuser3386109

2 Answers

2
votes

All resources referenced in the HTML file must be cached as well, and the baseURL needs to be a path to those cached resources.

-1
votes
 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];