开发者

Implement a web service or use scripts for iPhone App interaction?

I'm in the middle of working on my first native application with networking and I have a question regarding the best way for interacting with remote storage. In a perfect world I'd like to do the following.

  • Prompt the user for login information from the iPhone.
  • Verify the users credentials and connect to a MYSQL database hosted by myself.
  • Parse MYSQL data into a table view.
  • Allow the user to add or update information in the database.

I've read some similar questions posted, maybe something's lost in translation, but the two most common means I've come across are.

  • Create a web service for handling these requests using SOAP/REST/JSON (no experience doing this, but would like to learn if it's a better implementation)
  • Write PHP scripts (enough experience to get by) that will grab data username/password/requests securely from my NSURLRequest and echo the NSData as XML and parse it with an 开发者_如何学CNSXMLParser.

Are there other options? Is one a better implementation over the other? (web services come up more in searches)

Thank you in advance for taking the time to read my question and possibly clearing up any confusion.


Whoa! Web Services! Oh wait, calling a PHP script that returns JSON is actually also a web service. Well, that makes things simpler :-)

Yeah, so I would go for this:

  • Write a PHP script that returns JSON data (many tutorials available)
  • Protect the PHP script by setting up 'Basic access authentication' (Apache documentation)
  • Tell Apache to take the user database from your mysql database
  • Run your service on secure (HTTPS) web server (important because basic auth is not secure)

This way you can use almost all standard components on the iPhone side. NSURLConnection will talk HTTP(S) and there are excellent open source JSON parsers for Objective-C.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜