Kompi
Kompi

Reputation: 494

Save web pages with all their images, CSS, and other resources

I need to download a few web pages for later usee in my application, and I can't find an easy way to accomplish this task. I would prefer a solution where I don't need to parse the HTML to get the URLs of the images and other resources, but rather download these somehow automatically.

Upvotes: 1

Views: 1805

Answers (2)

Kompi
Kompi

Reputation: 494

OK guys, here is my solution:

  1. created my own cache object, derived from NSURLCache
  2. added to it a "state" enum variable, with the possible states of: SAVING, LOADING, NOTHING
  3. overwritten cachedResponseForRequest to do things according to the state
  4. SAVING: created a NSMutableDictionary to store every download request
  5. Downloaded the file in the request to a flat file, added the path to the file to the dictionary as an object, with the URL as the key
  6. LOADING: used this dictionary as they did in this example to load back the stored content: http://cocoawithlove.com/2010/09/substituting-local-data-for-remote.html
  7. set my cache object as the shared cache object using [NSURLCache setSharedURLCache:myCacheObject];

After this, when I want to save something I set the cache's state to SAVING, and load a request to an UIWebView. After this I set the state back to LOADING, load a request to an UIWebView, and if I stored my request previously, my cache will load it from the disk.

Upvotes: 1

matm
matm

Reputation: 7079

I think ASIHTTPRequest framework can be useful for you - try ASIWebPageRequest and see if it supports all features you need.

Upvotes: 0

Related Questions