PDA

View Full Version : Best way to retrieve data from a server?




neiltc13
Nov 10, 2008, 06:15 PM
I'm pretty beginner at iPhone coding and my application idea involves retrieving data from a server. While devising it, I had thought that it would be sufficient to store it in a MySQL database and hoped that iPhone would have a way of handling this.

However, I don't think that's possible. All I really want to do is download specific contents of a database as they are needed. So when a user switches from one page to another in my application, I want it to propagate that page with data.

Can anyone give me some pointers on the best way to do this? I had a look on the developer pages at Apple.com but it seems to involve storing a .sql file on the phone itself.



robbieduncan
Nov 11, 2008, 03:19 AM
Well you have all the normal networking functions so you could write a "library" to access MySQL via whatever protocol it uses. Easier though would be to write some code in your favourite language (Java/Ruby/PHP/whatever) and present a http-based front-end to the data...

Pim
Nov 11, 2008, 04:13 AM
How would you do that?

robbieduncan
Nov 11, 2008, 04:45 AM
How would you do that?

The server side is up to you. I would suggest returning XML data, but that is not iPhone specific and you should use whatever you are comfortable with. The iPhone side is covered in by using well documented (and discussed on here) NSURLConnection (http://developer.apple.com/iphone/library/documentation/Cocoa/Reference/Foundation/Classes/NSURLConnection_Class/Reference/Reference.html) class. Once you have the data it's up to you how you parse it/deal with it.

Pim
Nov 11, 2008, 04:46 AM
thanks :)

robbieduncan
Nov 11, 2008, 04:51 AM
thanks :)

If you do a search in this forum I think there are examples of using this. I'd recommend staying away from the simpler looking synchronous call and go with the async delegate-based methods. It's a bit more work but the sync method leaks memory :p