Adding an image in an html file with iOS

html, ios

Solution

You can include the image using:

<img src="img.png">

and

NSString *path = [[NSBundle mainBundle] bundlePath];
NSURL *baseURL = [NSURL fileURLWithPath:path];
[webView loadHTMLString:htmlString baseURL:baseURL];

You can copy your image `img.png` to documents directory for example and set the baseURL to be the Documents directory.

Update:

I found the source where I found out how to do it some time back. Maybe you can dig from there some more useful info: http://iphoneincubator.com/blog/windows-views/uiwebview-revisited

Problem

In my app I'm presenting a report of the app data. The report is a "self-generated" html file presented on an UIWebView. I need to include in the report (in the html file) an image that is stored in the device. At this moment I'm able to get the path of the image. It's something like "/var/mobile/Applications/A10781A1-DE2B-4651-ADFB-7A6AD9B3645A/Documents/EE20AF92-215E-4DF5-8E33-0713557A34C9" How can I include the image in the html file?

Original source