views:

83

answers:

2

I'm making an application that directly takes images from a site and downloads them into the apps Documents directory for use when the user doesn't have a data connection. The application will check the site for the latest post and update accordingly.

I've never done anything with databases before and thought that this would be easier to implement......since I'm only looking for one specific portion of the webpage.

Anyone ever do anything like this? Is this even possible?

Thanks for any responses! :)

+2  A: 

Do you control the website component, or is it sucking data from an arbitrary location?

If it's the former, it would make sense to output the data in XML for consumption by the iPhone. If it's the latter, you'd need to read and parse the (X)HTML DOM tree, which would be quite a bit more complex.

Either way, all you're doing is reading the data from the web server responsible.

Update: As a starter for ten, take a look at the URL Loading System Overview docs. (The NSURLConnection is a good starting point.)

middaparka
It's the latter, which is why I'm looking for a way to just download the page source as a string somehow...The latest resources that I want to download into the application are always shown on the default home page so I figured that if I could obtain the page source as a string, it would be easy for me to parse said string for the resource urls, timestamps, etc.
K-RAN
If it's not too much trouble, could you point me in the right direction on how to do this?
K-RAN
@K-RAN - I've updated my answer. Hope this helps.
middaparka
+3  A: 

Are you trying to mirror an entire, arbitrary pages for offline access, or do you just want to pick out specific images on certain page and store those?

Would this be for arbitrary pages, or for sites that are known in advance, so that you can inspect the HTML a little in advance, allowing you to pinpoint where on it your interesting images usually are?

You might want to have a look at hpple, an Objective-C version of hpricot, which can be used to parse HTML coming from web pages. If you know the DOM of the page that your app monitors, you could use it to extract the image names and then download them.

You're going to have to consider what to do if the site you're getting these images from changes its HTML/CSS dramatically. Bake too many specific assumptions into the app and it would need to be updated to work again. Without knowing specifics of what your app is trying to do, I can't tell if this is going to be an issue for you.

Joost Schuur
+1 for the assumption baking advice. :-)
middaparka