如何使用AFNetworking使用外部资源保存html文件? [英] How can I save a html file with external resources using AFNetworking?

查看:91
本文介绍了如何使用AFNetworking使用外部资源保存html文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用AFNetworking保存一个.html网页,但也想保存该网页内的资源(例如.css文件,.js文件,图像等),以便可以离线查看整个网页。



AFNetworking是否有可能,我将如何做?



谢谢!

解决方案

AFNetworking不需要这样做。相反,您要做的是使用支持磁盘缓存的 NSURLCache 子类(例如 Peter Steinberger的SDURLCache分支)。设置好之后,只需使用 UIWebView 加载URL(这不一定必须显示给用户),随后的加载应使用该本地缓存。 / p>

至少,不要浪费时间尝试自己编写一些东西来下载网页上的资产。此过程需要一个Web浏览器(其 UIWebView 符合条件)来确定需要加载的所有内容。


I would like to save a .html webpage with AFNetworking, but would also like to save the resources (such as .css files, .js files, images etc) within the webpage so that the whole webpage can be viewed offline.

Is this possible with AFNetworking, and how would I do it? Could a short example be posted please?

Thanks!

解决方案

AFNetworking is not necessary to do this. Instead, what you want to do is use an NSURLCache subclass that supports disk cacheing (such as Peter Steinberger's fork of SDURLCache). With that in place, just load up a URL using a UIWebView (this may not necessarily have to be displayed to a user), and subsequent loads should use that local cache.

At the very least, do not waste your time trying to write something on your own to download assets on a webpage. This process requires a web browser (which UIWebView qualifies as) to determine everything needed to load.

这篇关于如何使用AFNetworking使用外部资源保存html文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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