iPhone UIWebview — Saving an image already downloaded

柔情痞子 提交于 2019-12-02 17:47:31

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.

I don't think you can save the images using the UIWebview directly, you'r going to have to fetch the images manually...

disclaimer: I have not tried this.

If you can find out their names, UIImage responds to +(UIImage*)imageNamed:(NSString*) which the docs imply might get the image back from a device wide cache.

I'd be interested in knowing the results of any experiments.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!