Search code examples
swiftcore-bluetoothtvoswatchos

Is There Some Way To Have Core Bluetooth Support Peripheral Mode on WatchOS and TVOS?


This may seem like a strange question, as all the Apple lit seems to say "no problem," but the actual implementation says "problem."

I'm working on making an example SDK that is designed to work on all platforms (TV, Watch, iOS and Mac).

The SDK can run in both Central and Peripheral modes.

iOS and MacOS are no problem. I can get them running in either mode.

But when I try to get the same code to compile for Watch and TV, I get "'init(type:properties:value:permissions:)' is unavailable in tvOS" and "'init(type:primary:)' is unavailable in tvOS" (or WatchOS) errors when I try to instantiate mutable Services and Characteristics. The Navigator errors indicate that Apple has explicitly marked them as not available. The Displayed Compile Errors If I look the classes up in the docs, the classes are supported, but if I look up the only supported initializers, there's no support for Watch or TV.

Ipso facto, the classes aren't actually supported, as you can't instantiate them.

Does anyone see what I'm missing? Is there some way to instantiate mutable Service and Characteristic instances in a PeripheralManager in WatchOS or TVOS?


Solution

  • CoreBluetooth on tvOS and watchOS only supports central mode. You cannot act as a peripheral.

    This was covered in the 2017 WWDC session (link as of 2023 is here) where Core Bluetooth was introduced on these platforms:

    So we decided for accessory or for tvOS, you can only act as a Central device, and you can only connect to two simultaneous devices.

    ...

    And similarly, to watch OS, tvOS is a platform that relies on Bluetooth for its core system functionality

    Similarly, to the tvOS you can only act as a Central, meaning that you can connect out to accessories but you can't act as a peripheral to other devices.