What would be a good way to send some request from an Apple Watch to a user's MacOS devices?

I made a simple personal-use/testing watchOS app with a button that toggles the "mic muted" state of a chat application for Mac while on the same network. I'm now thinking about adapting this into a proper, distributable app with a companion Mac app.

This has me wondering: Is there some solution in Apple's various frameworks that would allow me to "broadcast" a request of this sort from my watch, either over the cloud or over the local network, to my companion Mac app without much in the way of user configuration? My current solution of "make an HTTP request to the hardcoded URI of a server running on my Mac" obviously isn't adaptable to different users or devices.

I considered Bonjour but it seems to be partially/fully deprecated and probably wouldn't let the user ensure only their own devices are controlled. Perhaps Handoff or something on CloudKit could be used for this purpose?

Replies

I considered Bonjour but it seems to be partially/fully deprecated

To be clear, Bonjour is in no way deprecated. Some older Bonjour APIs have been deprecated, but that’s only because we’ve replaced them with new and better APIs.

Having said that, networking from a watch directly to the Mac is tricky for two reasons:

  • watchOS does not support low-level networking APIs [1].

  • Even if it did, in many situations the watch is not associated with the user’s Wi-Fi. Rather, it uses Bluetooth to talk to the phone which then does network on its behalf.

I can see two approaches you might take here:

  • You could go via a server out on the wider Internet. If you don’t want to run your own server, you could use CloudKit for this.

  • You could use Core Bluetooth.

Each approach has its own pros and cons. For example, a server-based approach won’t work if the user’s Internet is down. And the Core Bluetooth approach requires that the watch be close to the Mac (with a few metres).

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] Unless you’re doing audio streaming. See Low-Level Networking on watchOS.