20

I want to use CFNetwork and Bonjour in conjunction to be able to have communications between my iPhone app and a Mac app. The app on the iPhone would have one button. Then on the Mac app, there will be a label. If the button is pushed on the iPhone app, the label changes on the Mac app.

Is there example code out there that can do this? If not, can someone lead me in the right direction?

Thanks!

objectiveccoder001
  • 2,929
  • 10
  • 43
  • 71

2 Answers2

44

Bill Dudney created a sample iPhone Bonjour application to demonstrate how to use Bonjour to discover and connect to two iPhones. I ported this example to the Mac to demonstrate how to do Bonjour discovery between the two platforms. Bill also provides a nice writeup of how he put together the Bonjour wrapper used in this example.

This is a very simple example, and with the Mac and iPhone clients it does something similar to what you want. Only minor modifications should be needed.

I show this in action in the video for the Networking session of my Advanced iPhone Development course on iTunes U.

Cœur
  • 32,421
  • 21
  • 173
  • 232
Brad Larson
  • 168,330
  • 45
  • 388
  • 563
  • 2
    @Elijah Wood - Simply change the base SDK to 4.0 (or whatever your current development environment supports) and his example should compile and run just fine. – Brad Larson Jul 15 '10 at 15:16
  • 1
    @BradLarson What would be the best way to save the selected server so the user doesn't have to choose the server again on next use? I would like my app to have the ability to remember which server the user picked and automatically connect to that sever in the future/or next launch, until the user decides to choose a different server. Any ideas? This has me stumped. Thanks. – 0SX Feb 28 '12 at 03:59
  • Does anyone know if this would be allowed on the iOS app store? – spring Mar 15 '13 at 21:38
  • Brand, is there anyway to send UI touch events communication between mac and ios apps ? Something like when I click at some point (lets say x-origin:100 , y-origin: 200) in my Mac app send that click event to iOS app and perform the click at the same point my iOS app. Is it possible ? – Bharath Vankireddy Mar 08 '16 at 14:56
  • @BradLarson hi, the bill.dudney links that you provided are no longer live. I want to build a peer-peer service that doesn't have a 8 peer limit like MCSession (I want unlimited or with something bigger than 8). From understanding Bonjour is the way to go. Do you have any references/links for Bill Dudney's Bonjour code in Swift? I'm not an Obj-C. Here is my question a little clearer: https://stackoverflow.com/questions/60349499/swift-does-the-bonjour-nsnetservicebrowser-have-a-peer-limit-larger-then-mcsess – Lance Samaria Feb 22 '20 at 08:46
6

Here i have created some simple sample application which exchange the data between iPhone and iMAC.

https://github.com/boobalaninfo/Bonjour-iOS-MAC-Apps

Boobalan
  • 737
  • 10
  • 9
  • Fantastic work with this.. I just wanted to know that is it possible to control UI events between these 2 apps you created for Mac and iOS app ? Something like when I click at some point (lets say x-origin:100 , y-origin: 200) in my Mac app send that click event to iOS app and perform the click at the same point my iOS app. Is it possible ? – Bharath Vankireddy Mar 08 '16 at 14:55
  • Of course it is very much possible. Send x,y position as a message and the iOS end receive and intercept that message to position event – Boobalan Jun 06 '16 at 06:32
  • Can you please send me any example if possible on how to do that ?In fact, I can send message from Mac app to iOS app using socket session but only the problem is that performing click event on iPhone screen irrespective of the which application is currently on foreground. Can you please give me some example code which do this functionality ? – Bharath Vankireddy Jun 07 '16 at 07:27
  • "performing click event on iPhone screen irrespective of the which application is currently on foreground" is seems to be tricky dude. I doubt whether it is possible or not! – Boobalan Jun 07 '16 at 09:40