CBPeripheralManager读/写

时间:2013-07-09 22:25:53

标签: ios core-bluetooth

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

这只能来自中环吗?

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

如果您尝试将数据从CBPeripheralManager发送到一个或多个连接的CBCentral,请使用已通知或已启用的特征。 CBPeripheralManager可以发送如下数据:

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

注意:确保CBCentral订阅您计划使用的特征。

至于从CBCentral读取数据,您可以发送"读取请求"使用上述方法,让CBCentral回复您正在寻找的数据。

相关问题