views:

151

answers:

2

Sorry if this is a stupid question, but I am new to this.

I am getting started with iPhone application development and would like to create an application that involves pulling data from from a web application.

Let's say the url is http://myapp.com/api/people/fetchall and it returns XML data.

  • How do I get this data into my iPhone App?

Update: After doing some research I decided that (on the Server-side) I want to implement a RESTful API that returns JSON. So my iPhone application will ultimately be a REST client.

Resources:

Here are some links that I have found helpful so far:

+1  A: 

Take a look at the Three20 project—the developer of the Facebook iPhone app, Joe Hewitt, made a lot of his work open-source, including a table-view class that can populate itself with data from the network.

Noah Witherspoon
+3  A: 

Ok, you've already broken down the main points, which is a good start.

Firstly, the web application will need its API to return data in a format that can be parsed easily by clients, whether they be iPhone apps or anything else. For this reason, a lot of web apps use JSON or XML. HTML is not a good format for transferring data, HTML is good for marking up text to be presented.

So firstly, write your web app to return XML or JSON formatted responses. If you have the time, you can make your web app do both, and specify as a parameter which format you want the response to be in.

To get the data down from the web app to your iPhone app, you're going to need to make a URL connection and download the data from one of your API calls.

For instance, if your API has a method that will return some information about a user, you'll need to build up an http request in your iPhone client, and send it to the server via the API URL, specifying whether it is a GET or PUT or other type of http request.

Interesting classes to look at for this are NSURLRequest and it's mutable counterpart and NSURLConnection and it's delegate protocol, NSURLConnectionDelegate.

Parsing the data will depend what format it is in. For XML, you can use the XML parser that is available in the iPhone SDK, NSXMLParser.

If you're going to be using JSON, you can use one of the JSON parsing libraries available on the iPhone. Personally, I've used TouchJSON and JSON-Framework.

To populate the table view, you will need to implement a couple of methods from the UITableViewDataSource methods, and a few from UITableViewDelegate. Reading up on the documentation for the UITableView class and the aforementioned protocols should give you enough information to start using them.

I hope this helps and gives you a starting point to learn more.

Jasarien
Sorry that was a typo originally. I meant to say "I assume XML is easier to work with"
Andrew