I have HTML and some images in the application for iPhone, sorted something like this:
html/ foo.html images/ bar.png
I can get bar.png in my UIWebView couple of different ways: either load foo.html from NSUrl , or return to the directory tree from the html directory:
<img src="../images/bar.png"/>
or by loading foo.html into a string, using loadHtmlString and using [[NSBundle mainBundle] bundleURL] as baseURL :
<img src="images/bar.png"/>
Both of these kinds are inconvenient, although in the first case, if I move the HTML files around, I have to redraw all the relative paths, and in the second case I have to ignore the actual path structure of the HTML files.
What I would like to do is
<img src="/images/bar.png"/>
- processing bundleURL as the root of the "site". Is there a way to make this work, or am I doomed to have it translated into file:///images/bar.png and not find the file?
source share