Kunal Balani
Kunal Balani

Reputation: 4789

Load Offline content in UIWebView

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

Upvotes: 0

Views: 1246

Answers (2)

Sudhir Chovatiya
Sudhir Chovatiya

Reputation: 61

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

Upvotes: -1

user3386109
user3386109

Reputation: 34829

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

Upvotes: 2

Related Questions