Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

How can connect iPhones, so that when a function is called on one iPhone, it calls functions on other iPhones through the web and can transfer parameters through the internet as well. Are there any other solutions rather than using a web host?

share|improve this question
 
Irrespective of the connectivity side of things, this won't be possible if the 2nd app is not running in the foreground (and doesn't have background capability, which very few things are entitled to have). –  Martin H Jun 15 '12 at 3:26
 
Yes I understand both users must have the application open. –  iPhone77 Jun 18 '12 at 2:31

1 Answer

up vote 1 down vote accepted

If the device you want to talk to is physically within range, you can either use Bluetooth (GameKit API is very simple) or the more complex Bonjour Protocol for device discovery in the local network.

If your devices are physically not in range, you will most likely not be able to avoid some kind of server that has a (REST?) API which handles requests.

share|improve this answer
 
I plan on using a server of some kind to handle the requests, but I am not sure which is a good one too use or how to implement it. Do you know of any server APIs or documentation on this? –  iPhone77 Jun 15 '12 at 14:45
 
It's fairly easy to write a REST server, which you can easily communicate with via iPhone. The principle is the same as using the Twitter API. You create an NSURLConnection (or use a wrapper like github.com/samvermette/SVHTTPRequest which makes that even easier) and let that request open a specific URL on your server using POST/GET/PUT/DELETE. (Everytime you open a page in your browser a GET is executed. Everytime you submit a form on a webpage a POST is executed... - No magic.) –  wasabii Jun 15 '12 at 15:24
 
The NSURLConnection then provides you with the response it received from the website it opened. You can implement the server side logic using various different languages/scripts. Depends on what you like and what you're going for. You can do a simple PHP page that evaluates the GET parameters it received from NSURLConnection and provides the appropriate response which your iPhone then receives. A framework to do that could be recessframework.org for instance. –  wasabii Jun 15 '12 at 15:26
 
An iPhone(A) to iPhone(B) communication could then be (naïvely) realized by having iPhone A POST data to your server's API that you implemented using PHP. Said data then gets written into your MySQL database. Your other iPhone B periodically* requests a different URL using GET and asks whether there is any new data in the database. The server sends 0 if not and 1 if there's some. If the response was 1 iPhone B then requests the new data. - *NOTE: Periodically means your iPhone is POLLING information which results in increased server load and more battery usage. –  wasabii Jun 15 '12 at 15:29
 
If you're doing this for the first time, don't worry about stuff like that though and simply poll as much as your heart desires. You can switch to pushing information using APNS (Apple Push Notification Service) later on. –  wasabii Jun 15 '12 at 15:32
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.