views:

366

answers:

2

When Connected:
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.

When Offline:
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 NOT displayed.

Possible Cause:
I guess the problem might be that the image paths (<img src="photo_files/..." />) 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?

Question:
How do I get it so that I can display local images in a UIWebView without modifying the html source?

*(Assume valid local paths .../Photos/photos.html, and Photos/photo_files/(image files).jpg all under the documents directory path)*

HTML page source

...

<html>
<body>

<h1>Photo Gallery</h1>


<img src="photo_files/app_IMG_01.jpg" /><br />
<img src="photo_files/app_IMG_0100.jpg" /><br />
<img src="photo_files/app_IMG_0066.jpg" /><br />


</body>
</html>

Objective-C source

...

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

I found out why this was not working for me. It was related to something totally different. UIWebView does not seem to have any problems with relative paths.

RexOnRoids
A: 

It's better if you provide your solution here so that someone can reference that.

nirvana22112