Download and cache entire web page on ios

佐手、 提交于 2019-12-22 11:22:05

问题


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.

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 ....

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.

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..!

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..?

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


回答1:


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.



来源:https://stackoverflow.com/questions/16683411/download-and-cache-entire-web-page-on-ios

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