iosuiwebview

How to refer a local image file from UIWebView's HTML on iPhone?


I would like to use <img src="temp.jpg" /> in my UIWebView's HTML.
How can I refer to a local file named temp.jpg to save precious loading time?

Of course the obvious choice would be <img src=".\temp.jpg" /> but I have no idea where my root is...


Solution

  • NSURL *url=[[NSBundle mainBundle] bundleURL];
    [webView loadHTMLString:string baseURL:url];
    

    This let's the root be the app's main bundle.