For a recent project I encountered the following requirements:
- Download and store HTML documents that are rendered using the UIWebView class.
- Download and store the external documents referenced in the HTML, like images, so that they, along with the HTML documents, are available in non-networked situations.
- Use the same HTML documents and external documents as the body of in-app generated Emails.
The challenge was to devise a scheme whereby the same HTML documents can be used for both rendering content within the app under non-networked situations and to provide the exact same user experience within the Email body; a clear Catch-22!
There are a number of possible approaches (see page 10 of Nick’s presentation, but the one we choose was to use complete URL’s for all externally referenced documents within the HTML (for example, all images are referenced on a CDN). We choose this route as it provides the simplest way to support the Email requirement.
In this case, this event listener queries for all image tags and modifies the src attribute by stripping all of the URL except for the image file name. For example if our image tag looked like this,
<img src="http://www.pervasentcdn.com/pervasent.jpg" class="logo" alt="Pervasent" />
it would be come this
<img src="pervasent.jpg" class="logo" alt="Pervasent" />
and thus achieves our goal.