How do native apps on phone devices communicate with web-based databases?
For iPhone or iPad devices, what is the recommended way of communicating with a web-based database?
For example, if I want to show a list of high scores, or submit a users high score, how woul开发者_如何转开发d I connect to a database to retrieve this info?
Is there a best practice that works across multiple devices (such as the Pre)...
The most common means of interacting with a server in this manner are via the NSString stringWithContentsOfURL:encoding:error:
method (and other related methods in NSString) and the NSURLConnection class, which is capable of performing asynchronous background requests.
Both of the above linked class reference documents contain code samples (see the "Related sample code" section at the top of each).
Additionally, there are 3rd party solutions available, such as the commonly used ASIHTTPRequest class.
As such, you'd use these to communicate with a server-side scripting platform which would then return the data via JSON, XML, etc. In terms of parsing JSON on iOS, the json-framework project is rather nice.
RESTful Webservice
produces easily parseable JSON or XML responses (frameworks exist on iPhone to make your life easier). TouchXML, SBJson, ASIHTTPRequest, etc
SOAP is generally considered too heavy a protocol for devices such as iphone
精彩评论