iPhone UIWebview - 保存已下载的图像

5 iphone uiwebview

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

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

squ*_*art 5

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

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

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.
Run Code Online (Sandbox Code Playgroud)


hha*_*fez 0

我不认为你可以直接使用 UIWebview 保存图像,你必须手动获取图像......