Save the web page offline for read later on iOS
I am trying to make a app which can save the web page offline for later reading. I found ASIWebPageRequest proje开发者_JS百科ct can cache the web content. However, I have a question, if I have lots of web page, such as 100 pages, each one contains many images. Is it a good solution for it? Or this project can dynamic load content from it cache?
I am thinking another solution, but I am not sure if it's possible and how to implement. Could you help give some suggestion?
When loading the page, the iOS parsing the http content and save all resources, such as image, css, js, to the database. When accessing it next time, it get those resource database. Is it possible?
Best Regards,
Yes it is possible.
You can do a regexp on the Content returned by a NSURLRequest and save all links and images to disk. My suggestion is, replace the path with the regexp and rename images/resources to be a md5 of their content. so if you get an image twice, it will only download once :)
I wrote a lot of code for this, but i cannot publish it :( But it is possible and it works, takes about 100 lines.
Please +1 this if it helped you. thanks :)
This looks like a perfect opportunity to use NSURLCache (http://www.nshipster.com/nsurlcache/). It operates in a number of modes, two of which would cover your requirements. At first use, you'd use it to fill the cache. On subsequent uses, you could use it in ReturnCacheDataDontLoad
mode. This would completely eliminate any problems you would otherwise have maintaining/altering relative paths, cross-domain issues and so on.
精彩评论