views:

342

answers:

3

I have some apps in mind to control things in my Mac from the iPhone. Probably the simplest thing to do would be to make the iPhone simulate a keyboard and then handle key events on the mac.

What do you think it's the best way to communicate iphone with the mac? Can I use GameKit for that? HTTP?

+3  A: 

You can't use GameKit, because that framework is not present on the Mac. The way to do this is using NSNetService and NSNetServiceBrowser, which encapsulate using Bonjour to autodiscover available connections. I'd check out the sample code ("Bonjour Web", "CocoaEcho", and others) to help you get started.

Be aware, though, that these classes look pleasant enough at first, but can be the source of endless frustration. (They were for me)

Dave DeLong
sounds like a good starting point, thanks!
Jorge Bernal
+1  A: 

If you're thinking about some sort of remote control, I would suggest bluetooth and the new frameworks that are out there. I've only done iphone to iphone though, and not iphone to mac.

TahoeWolverine
+2  A: 

You can write a simple web server and run it on your Mac, probably on a custom port, then have your iPhone talk to the web serter to send it commands. This is what I do in Keyboard Maestro/Keyboard Maestro Control.

There are a bunch of issues to be dealt with though, not least of which is that you can't use https (because you can't have a proper certificate for each Mac and the iPhone wont allow https connections to self signed certificates), so you have to decide how and how much of your communication channel to protect and then be careful not to run afoul of the export restriction issues.

Peter N Lewis