在ios上下载并缓存整个网页 [英] Download and cache entire web page on ios

查看:377
本文介绍了在ios上下载并缓存整个网页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要下载整个网页并将其存储在应用程序的文档目录中,并在用户下次访问时从缓存中加载它。

I need to download an entire webPage and store it in app's documents directory and load it from the cache the next time user visits.

无论我搜索多少,我总是最终得到 ASIWebPageRequest .. !!尽管如此,它仍然有效,它已经很老了并且已经弃用了。所以我正在寻找一些替代方案。我试图避免它的另一个原因是因为....

No matter how much I search, I always end up with ASIWebPageRequest..!! even though, it works, its very old and deprecated.So I am looking for some alternatives. Another reason I am trying to avoid it is because ....


这是一个完全重新实现的URL加载系统,基于非常低的
级构造(CFNetwork)。因此,当Apple对其$ b​​ $ b高级库(NSURLConnection,NSCache)进行改进时,ASIHTTP不会获得
这些进步。

It is a completely reimplemented URL loading system, based on very low level constructs (CFNetwork). So as Apple makes improvements to their high level libraries (NSURLConnection, NSCache) ASIHTTP doesn't get those advancements.

因此,我试过这个来自苹果的示例代码,它给我一个 NSData 我给它的任何网址。但是,当我尝试将 NSData 加载到 UIWebView 中时,使用 loadData:MIMEType:textEncodingName :baseURL:方法,我需要将mimetype指定为text / html,现在网页中的图片和链接都没有加载..!

Hence, I tried this sample code from apple, It gives me a NSData of whichever url i feed it. but, when I try to load this NSData into UIWebView using, loadData:MIMEType:textEncodingName:baseURL: method, I need to specify the mimetype as "text/html" , now the images and links in the webpage doesn't load..!

我还有其他方法可以用来实现它吗?也许使用 NSURLCache ..?但是怎么样?
有没有其他好的图书馆我可以使用或者我坚持使用ASIWebPageRequest ..?

Is there any other way I can use to achieve it..? perhaps using NSURLCache..? but how?? Is there any other good libraries ou there that i can use or am I stuck with ASIWebPageRequest..?

仅供参考,我需要用所有js,css等下载整个网页。

FYI, I need to download the entire webpage with all js, css etc.

推荐答案

关于ASI的替代方案, AFNetworking 现在更受欢迎。如果你想缓存你的内容,你应该看看 NSURLCacheStoragePolicy NSURLCache

About an alternative of ASI, AFNetworking is much more popular now. If you want to cache your content, you should have a look at NSURLCacheStoragePolicy and NSURLCache.

这篇关于在ios上下载并缓存整个网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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