iOS Device communication - iphone

I am keen to get some apps built that can communicate with other devices/ web etc. i have played around with FTP and can get so far. But what is the best way to do this? We don't have any Servers with databases etc, but do have a site that we are currently uploading and downloading files to.
can anyone suggest a good/ better way to get the device to send/ receive files?
thanks
sam

If it's HTTP communication you're wanting to do, the simplest and most powerful tool is ASIHTTPRequest.
HTTP is the protocol your web browser uses to talk to web servers. If you have a site you're storing and downloading files at, it's almost certainly HTTP you're talking to it.

For iOS device to device communication one can use Bump API.
EDIT: I don't know of a generic framework for device <-> server communications, but having built applications that use web services of other providers like Yelp, Yahoo, Google Maps, I would say the way to go for this is to have REST based web services which exchange data in JSON format.

Related

Publish Subscribe from WCF to Android, Iphone, WP7

Is there a framework that supports publishing (pushing) messages from a WCF service (REST or SOAP) to various clients like IPhone, Android and WP7? I'm thinking I can use the WSDualHttpBinding to do dual communication between WCF and WP7. However, I'm assuming WSDualHttpBinding is not supported in the other two platforms since is not a WS-* standard and there's a lot of stuff that WCF does to establish a receiving channel on the client side. Is there any other way to accomplish this? How would I about rolling my own?
I'm thinking about exposing my WCF service as a restful endpoint and implement a COMET style pub/sub and calling it good.
I'm stuck. Any help would be greatly appreciated.
Since you already have a solution for WP7, you could probably use urbanairship.com to handle the pushes for iPhone and Android. I've used them on a prior project with good results. (I don't work for them.)
I found this "Cloud to Device Messaging", C2DM, yesterday and thought it may serve your question:
http://www.makeurownrules.com/archives/category/android
Have you considered using SignalR? It'll fallback gracefully from WebSockets & Server-Side Events through to long polling. There's a mono implementation of the client-side library.
We're successfully using it in a large-scale realtime application and it works a treat. A bit further down this page it details how to communicate with clients from outside the SignalR infrastructure which may be useful if you want to talk to clients from your WCF service.
Cheers,
Dean

iPhone network communication with pc

I want to make an iPhone app and an application (server) which runs on a PC with Windows. Is there any easy way to do this on the client side (the iPhone), like a library or something?
Looking on Google I found cocoaasyncsocket and xmppframework, but the last commits were done some time ago and before I start my project I want to know if there are other (better) possibilities out there
One option would be to run a web server on the PC, with a set of REST-based services. This approach gives you lots of options for implementation on the server-side, and you'll have lots of possible frameworks to choose from on the client-side as well. One framework you could use on the iPhone is ASIHTTPRequest.
There are lots of advantages to using a web-based approach. There are HTTP frameworks built for almost every device and platform, so if you ever want to interact with the server from the web, an Android device, etc., there will be many tools to help you do that. There are also lots of great tools out there for debugging HTTP interactions.
You could also use a SOAP-based API, but in my opinion SOAP tends to be more complicated than its worth.

How does iphone apps interact with server?

I am a new programmer who is new to iPhone development and server stuff. I have a lot of questions to ask.
You don't have to answer all the questions; any help is appreciated!
How does iPhone apps interact with server?
Is there a particular kind of server i should use to interact iphone app with server?
If there is no particular kind of server then what kind of server can be used?
What are their advantages and disadvantages?
What should the iPhone app (which is the client) do in order to interact with the server?
How does the server know which iPhone to send data to?
What should the server do in order to interact with iPhone app (client)?
Your best bet is to have your iPhone make web requests of a web server. Your iPhone app acts just like a web browser, making http requests to a web server, and parsing the response.
I'm building an app right now that hits PHP scripts I've written that do database work, etc, and return JSON objects. It's not fancy--I could have built a whole SOAP or RPC web service, but I didn't do that, it just makes GET requests with query-string arguments.
There are handy libraries you want to know about. Google "iPhone JSON" to find the JSON library written by Stig Brautaset, that's the one most people seem to be using. Also, rather than putting yourself through all the hoops that the iPhone's built-in web client framework requires, go get ASIHTTPRequest, a very powerful and MUCH simplified web client library.
As a general rule, you want to do as much processing on the server as possible. For instance, there's a place in my app I'm searching for events happening within a user-specified range of their local coordinates ("within 10 miles of me"). I wrote PHP to build a latitude/longitude bounding box, and query from the database based on that. That's WAY faster than bringing a bunch of events down and then asking Core Location to calculate their distance from where I'm standing.
You've asked quite a few questions so I'll try my best to answer them all:
First, you need to be a bit clearer, what type of server are you talking about? Email server, web server, lolcat server, it depends.
At the basic level, the iphone communicates over the internet. The internet uses Internet Protocol, and there are two standard protocols built atop of IP: Transmission Control Protocol, and User Datagram Protocol. Each has it's own uses and functions.
TCP/IP and UDP/IP make up the backbone of internet communication.
A more specific application protocol is built atop of these two internet protocols, with a specific format to a given application. For example, HTTP is the standard protocol for transferring HTML and other Web information between a web server to a web browser client, over TCP.
So, your iPhone would use whatever protocol is required to commuincate with the server. For more common server communication, the iOS SDK provides methods to construct messages (for example if you wish to make an HTTP request to a web server, you can use initWithContentsOfURL to send a GET request).
If you built a custom server, then you will need construct the required message protocol on the iphone, and send it to the server, using either TCP or UDP (whatever your custom server expects).

Do most iPhone apps communicate via web services?

Do most of the popular iPhone apps that communicate with a back end Internet server communicate via web services? I was assuming this was the case.
Some apps I'm thinking about would be: Facebook, Bloomberg, NY Times, ESPN, etc.
Well a web service is just an API - Application Programming Interface
The apps you mentioned would probably all implement their own API for exchanging data between the client and the server so yeah, I would say the answer is yes. You can implement your own API via XML, JSON etc. You just need to define the protocol. You can implement existing concepts in your own apps. Have a look at the following:
REST
SOAP
JSON
Most of the Apps that I've written use web services of some sort, I prefer being RESTful, but I have been forced to use SOAP.

iPhone application architectures

Can you anyone point me to specific books or maybe give me a quick overview of how architectures of data-driven iPhone applications look like? For example, let's say you're implementing an application that searches online shopping sites and gives you recommendations..etc. Is it a common pattern to establish a hosted back-end of webservices which does all the database/shopping site API connections/webservices work and have the iPhone app consume services on this backend? or do you put everything in the iPhone application? Also, if you are establshing a web-services back-end, is it better to use REST/JSON vs REST/XML vs SOAP/XML...etc?
Thanks
To answer the first part of your question, I'd say that's up to you. If there's a lot of processing that needs doing between the web service and the iPhone, then maybe you should have your own backend server doing that processing before sending it to the iPhone. However, if you just need the data from the web service as-is on the iPhone, then just consume it directly.
As for the different formats, with the iPhone smaller is always better when it comes to network traffic. Stick with using REST for sure so you minimize data that needs to be transferred from the iPhone. As for JSON vs XML, obviously JSON is more lightweight which makes it a better candidate for the iPhone generally, but if your data requires a representation more complex than JSON can offer, then go with XML. Don't do SOAP if you can at all avoid it. It's just too heavyweight and will drain the iPhone's battery much more quickly with many requests.
If you are curious about the architecture and implementation details of a data-driven iPhone app, take a look at all of Apple's docs and tutorials about Core Data on the iPhone.