1

我在 iPhone 上使用 CoreBluetooth,我想知道是否有办法从外围设备端进行读/写请求。我已经设置了一个 CBPeripheralManager 和一个委托,但是通过查看文档我看不到任何从外围设备的属性甚至它自己的属性中读取的方法。

这只能来自中环吗?

4

2 回答 2

1

是的。CoreBluetooth 假设如果您正在设置外围设备,您不会查询蓝牙堆栈来检索有关您自己的属性,而是会简单地查询一些内部数据结构。

于 2013-10-24T02:47:08.530 回答
0

如果您尝试将数据从 a 发送CBPeripheralManager到一个或多个已连接CBCentral的 s,请使用已启用通知或指示的特性。可以像这样CBPeripheralManager发送数据:

let success = peripheralManager.updateValue(data, forCharacteristic: characteristic,
    onSubscribedCentrals: [central])
if !success {
    // cache the data until the delegate method peripheralManagerIsReadyToUpdateSubscribers is called.
}

注意:确保CBCentrals 订阅您计划使用的特性。

至于从 a 中读取数据CBCentral,您可以使用上述方法发送“读取请求”,并使用CBCentral您要查找的数据进行响应。

于 2016-02-06T22:21:58.743 回答