I plan to have a MySQL database on my server, from which I would query and retrieve several different types of data. Namely, I'd be retrieving data from CHAR (text), date, and BLOB (image) columns. This data would not be very large; images would be low- to mid-quality and quite small, maybe a few KB each. I'd like to send a POST request to my server with query parameters in it (and login credentials), and receive the result set of that query, in a format suitable for manipulating in XCode and displaying it on the user's screen.
I already have an app on the store that uploads data to a PHP form on my server, which then talks to a MySQL database, so that part of things isn't a problem. However, I don't have any experience with retrieving complex result sets and parsing them for use in an app.
What would be the most effective, and least memory-intensive, way to do this? I'd like things to load as quickly as possible; I'd be limiting the size of my result sets as well (i.e. only 20 records at a time) so there wouldn't be a large amount of data to retrieve in any one request. Initially I feel like I should look into sending the data from the PHP form to the phone in an XML format and then parsing it, but I'm not very familiar with XML and have read that it can be more expensive than other solutions memory-wise.
If you want an idea of what I'm trying to achieve, iTunes or the App Store is a perfect example.
1) The user makes a selection (i.e. the "Games" category on the App Store) 2) The phone retrieves data from a server and spends a few seconds loading it 3) The "result set" is shown: 25 rows, each one with a small image (the app's icon), some text (the app's name), and maybe some supporting information like the app's developer and the rating 4) The user taps "more" if they want further results, and the phone retrieves the next 25
I'm doing similar stuff to what you mention, using an HTTP GET (rather than a POST) and handling XML content coming back. I think XML is pretty much the standard for what you want to do, and there is good support for XML parsing in the iPhone SDK (using NSXmlParser). There is no issue with memory size or execution. There is a bit of a learning curve if you have no familiarity with XML, but IMO its worth climbing it because XML is ubiquitous as far as interacting with servers of any kind these days.
A question. What would be the best way to incorporate images? It doesn't look like I can easily do that in XML, unless maybe I encode it (i.e. base-64) server-side, send it as XML, and then decode it on the device?
A question. What would be the best way to incorporate images? It doesn't look like I can easily do that in XML, unless maybe I encode it (i.e. base-64) server-side, send it as XML, and then decode it on the device?
I would think you could do it with multipart content where the image is included in a part with 'Content-Transfer-Encoding: binary' and is therefore not base64 encoded.
I am not doing this exact thing, but I am doing the reverse in a sense, where I am submitting an HTTP POST to my server that contains multipart content, where one part is audio data. I am just sending that in raw form in a section that uses binary for Content-Transfer-Encoding. If you are in control of the code both sending and receiving I don't see why you would need to do base64 encoding.
I guess what I'm asking is, is there a way to receive the images inline as an element in the XML document, and then parsed by the NSXMLParser? Or would images need to be downloaded and handled separately?
I guess what I'm asking is, is there a way to receive the images inline as an element in the XML document, and then parsed by the NSXMLParser? Or would images need to be downloaded and handled separately?
I would think you could have the images contained in the XML document. You would just want to have them in a CDATA section that contains the binary data.
I would think you could have the images contained in the XML document. You would just want to have them in a CDATA section that contains the binary data.
XML may contain encoded binary data or it may contain just the url for the images which can be then used to download.
Yeah, it looks like embedding the binary data directly into the XML document will be a problem for the parser. I could either embed the URLs (which might be difficult since the images will be contained as BLOBs in an SQL database), or base64 encode the images in the PHP form I use to query the database, embed them in the XML document, send the whole thing back to the phone's XML parser, and use a base64 decoder class in Cocoa to bring the images back to data I can use.