Slee
Slee

Reputation: 28248

view downloaded images in UIWebView

I need to display a UIWebView that shows images that have been downloaded by the app. I generate my HTML and set it like so:

UIWebView *webView = [[UIWebView alloc] initWithFrame:self.view.bounds];
        [webView loadHTMLString:messageBody baseURL:nil];
        [self.view webView];

The images in my generated HTML look like this:

<img src="file://Users//Max//Library//Application%20Support//iPhone%20Simulator//5.1//Applications//CDA9EC67-01BA-4AD8-B18B-E467A54B464C//Documents//18//l4c050-01w_tn.jpg" height="60" /> 

The images show up as broken, what am I missing here?

Upvotes: 0

Views: 218

Answers (1)

joern
joern

Reputation: 27620

You are using an absolute path to your Desktop computer in your images. As soon as you try to run your app on a device this won't work, because the app cannot reach files on your desktop computer.

The right approach would be to use relative paths in your images and then set the baseURL parameter to the folder of your devices file system where you store the images.

Upvotes: 1

Related Questions