Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to display locally stored images with a UIWebview
    primarykey
    data
    text
    <p><strong>When Connected:</strong> <br /> I have a simple HTML page with some image elements that reference images in a subdirectory as in (src="images/someimage.jpg"). This page displays fine when accessed remotely via an internet connection. </p> <p><strong>When Offline:</strong> <br /> I store the above HTML page locally to the apps documents directory for offline viewing. The local HTML page is loaded and displayed fine with the UIWebView -- the PROBLEM is that the images in the HTML file are <strong>NOT</strong> displayed. </p> <p><strong>Possible Cause:</strong><br /> I guess the problem might be that the image paths (<code>&lt;img src="photo_files/..." /&gt;</code>) are not resolved to absolute paths locally? How do I get it so that I can display local images in a UIWebView without modifying the html source? I don't wanna have to go in there and manually change each of the image paths to the documents directory paths...How do I get the local images to display correctly on my UIWebView?</p> <p><strong>Question:</strong><br /> How do I get it so that I can display local images in a UIWebView without modifying the html source?</p> <p><em>(Assume valid local paths .../Photos/photos.html, and Photos/photo_files/(image files).jpg all under the documents directory path)</em></p> <p>HTML page source</p> <p>...</p> <pre><code>&lt;html&gt; &lt;body&gt; &lt;h1&gt;Photo Gallery&lt;/h1&gt; &lt;img src="photo_files/app_IMG_01.jpg" /&gt;&lt;br /&gt; &lt;img src="photo_files/app_IMG_0100.jpg" /&gt;&lt;br /&gt; &lt;img src="photo_files/app_IMG_0066.jpg" /&gt;&lt;br /&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Objective-C source</p> <p>...</p> <pre><code> NSFileManager* myManager = [NSFileManager defaultManager]; if([myManager fileExistsAtPath:[[self documentsDirectory] stringByAppendingPathComponent:@"/Photos/photos.html"]]){ NSLog(@"Loading Saved Copy!"); urlAddress = [[self documentsDirectory] stringByAppendingPathComponent:@"/Photos/photos.html"]; //Create a URL object. NSURL *url = [NSURL fileURLWithPath:[[self documentsDirectory] stringByAppendingPathComponent:@"/Photos/photos.html"] isDirectory:NO]; //URL Requst Object NSURLRequest *requestObj = [NSURLRequest requestWithURL:url]; //Load the request in the UIWebView. [webView loadRequest:requestObj]; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload