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!

2 Answers 2

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.

5
  • 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. Commented Jul 15, 2010 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
    Commented Feb 28, 2012 at 3:59
  • Does anyone know if this would be allowed on the iOS app store?
    – spring
    Commented Mar 15, 2013 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 ? Commented Mar 8, 2016 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: stackoverflow.com/questions/60349499/… Commented Feb 22, 2020 at 8: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

4
  • 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 ? Commented Mar 8, 2016 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
    Commented Jun 6, 2016 at 6: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 ? Commented Jun 7, 2016 at 7: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
    Commented Jun 7, 2016 at 9:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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