IPhone UIWebview - saving an already downloaded image

I have an iPhone app with built-in UIWebview (Safari). I would like to be able to store images from certain web pages locally.

Can I programmatically access the path that UIWebview uploads images to? Or do I need to parse the HTML and then find the image resource on the network and download it again?

+5
source share
3 answers

I don't know if you can access pre-loaded images from Safari's cache ...

However, you can easily find image URLs without HTML parsing, do a little javascript instead:

NSString *script = @"var n = document.images.length; var names = [];"
                    "for (var i = 0; i < n; i++) {"
                    "     names.push(document.images[i].src);"
                    "} String(names);";
NSString *urls = [webView stringByEvaluatingJavaScriptFromString:script];
// urls contains a comma-separated list of the image URLs.
+5
source

, UIWebview , ...

0

Disclaimer: I have not tried this.

If you can find out their names, UIImage responds to + (UIImage *) imageNamed: (NSString *), which, according to the document, can return an image from the device’s cache.

I would be interested to know the results of any experiments.

0
source

All Articles