有什么方法可以让 Core Bluetooth 在 WatchOS 和 TVOS 上支持外设模式?

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

这似乎是一个奇怪的问题,因为所有 Apple 点亮 似乎 都说 "no problem," 但实际实现说 "problem."

我正在制作一个适用于所有平台(TV、Watch、iOS 和 Mac)的示例 SDK。

SDK 可以运行 中央模式和外围模式。

iOS和MacOS都没有问题。我可以在任何一种模式下 运行ning。

但是当我尝试为 Watch 和 TV 编译相同的代码时,我得到“'init(type:properties:value:permissions:)' is unavailable in tvOS”和“'init(type:primary:)' is unavailable in tv OS”(或 WatchOS)错误,当我尝试实例化可变服务和特征时。 Navigator 错误表明 Apple 已将它们明确标记为不可用。 如果 I look the classes up in the docs, the classes are supported, but if I look up the only supported initializers,不支持 Watch 或 TV。

事实上,类 实际上不受支持,因为您无法实例化它们。

有人看到我遗漏了什么吗?有什么方法可以在 WatchOS 或 TVOS 的 PeripheralManager 中实例化可变服务和特征实例?

tvOS 和 watchOS 上的 CoreBluetooth 仅支持中央模式。你不能充当外设。

2017 WWDC session 在这些平台上引入了 Core Bluetooth 中对此进行了介绍:

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.