views:

630

answers:

4

I'm thinking about creating an application for the iPhone and Android that will need to access a common backend to retrieve account information. Can both access a web service over https? What other way would allow me to have one interface to the backend that is accessible by both?

+4  A: 

They both work over http and https which is a common enough protocol. I would suggest you go with a RESTful web service so you expose your service via URI's like http://www.myservice.com/weather/zip/98007 which would return an XML blob that can be parsed by the client.

aleemb
If it is possible try to use json instead of xml. This will reduce the data size that is transmitted and if you are using google gson also reduce the work needed to get your data.
Janusz
+1  A: 

I'd recommend using a RESTful web service backend, which is all standard HTTP and/or HTTPS. If you can use Ruby on Rails, its default scaffolding will get you about 99% of the way there and for the iPhone there is an open source project called ObjectiveResource that will automate your communication with this Rails backend. I haven't investigated yet what options are available on Android but since it is all simple HTTP it should be straightforward. I am not the maintainer of ObjectiveResource but I have contributed some code. You can check it out here:

http://iphoneonrails.com

Adam Alexander
A: 

One good approach I have seen used with other services is to write the backend in such a way that it can feed data back in different types - for Android an XML response is best, but for the iPhone sending back plist data is preferred (though it can also work with XML if required). In both cases it's easier to simply POST updates back to the server than to wrap an update in XML.

Both platforms should be able to use whatever form of authentication you wish to use, the iPhone I know supports all methods of HTTP authentication.

Kendall Helmstetter Gelner
@kendall: but for the iPhone sending back plist data is preferred - can you let me know why plist is preferred over xml?
Raj
Using plist data means you automatically have the return data easily parsed into an array or dictionary. If you use XML you have to spend more effort parsing results. Also using plists gives you the potential to use binary plists to minimize the amount of data to transfer and lower parse time.
Kendall Helmstetter Gelner
JSON is a preferable format to plists, since it is only marginally less space efficient than binary plists, it can (almost) as easily be parsed into native Cocoa objects (using json-framework), and it is a web standard, so you can use the same data easily on iOS, Android, and any other client platform.
Nick Forge
After going through a lot of projects I would say technically plists are still preferable, just because they are more robust in terms of types coming back, and generally you'll not get back NSNull objects like you can from a JSON parse under some conditions. But, most server side people only know JSON and it's probably better to stick with what they are most happy and comfortable with.
Kendall Helmstetter Gelner
+2  A: 

if you are starting from nothing, i'd definitely go with RESTful service that returns/accepts JSON... there are plenty of libraries for both platforms that will accept JSON and turn it into arrays and dictionaries.

john ellis