iPhone UIWebview - 保存已下载的图像 [英] iPhone UIWebview -- Saving an image already downloaded

查看:110
本文介绍了iPhone UIWebview - 保存已下载的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有嵌入式UIWebview(Safari)控件的iPhone应用程序。我希望能够在本地存储来自某些网页的图像。

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.

我能以编程方式访问UIWebview下载图像的路径吗?或者我是否需要解析HTML然后再在网上找到图像资源并再次下载?

Can I programmatically access the path where UIWebview downloads images? Or do I need to parse the HTML and then go find the image resource out on the net and download it again?

推荐答案

我不知道你是否可以从Safari的缓存中访问预加载的图像...

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

但是你可以通过运行一些javascript来轻松找到图像URL而无需解析HTML :

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.

这篇关于iPhone UIWebview - 保存已下载的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆