iPhone UIWebview — Saving an image already downloaded

后端 未结 3 2057
时光取名叫无心
时光取名叫无心 2021-02-01 00:08

I have an iPhone app with an embedded UIWebview (Safari) control. I\'d like to be able to store the images from certain webpages locally.

Can I programmatically acces

3条回答
  •  终归单人心
    2021-02-01 00:22

    I do not know if you can access the preloaded images from Safari's cache...

    However you can easily find the image URLs without parsing HTML, by running a bit of 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.
    

提交回复
热议问题