gpt4 book ai didi

ios - BLE 外围设备是否会在订阅时自动发送特性值?

转载 作者:行者123 更新时间:2023-11-29 12:29:08 25 4
gpt4 key购买 nike

借助 CoreBluetooth,我可以订阅外围设备的 CBCharacteristic,使用:

[peripheral setNotifyValue:YES forCharacteristic:characteristic]

订阅后,我是否应该期望获得 peripheral:didUpdateValueForCharacteristic:error:CBPeripheral 委托(delegate)回调,其特征在其 value< 中设置了最新值属性?

或者要求中央首先显式读取该值,然后订阅该特征是否更标准?按照“标准”,我想知道这是否在某处的 BLE 规范中被调用或明确推荐(看了一下,找不到任何东西)。

最佳答案

documentation对此非常清楚:

This method is invoked when your app calls the readValueForCharacteristic: method, or when the peripheral notifies your app that the value of the characteristic for which notifications and indications are enabled (via a successful call to setNotifyValue:forCharacteristic:) has changed.

您不会在订阅后立即获得委托(delegate)回调 peripheral:didUpdateValueForCharacteristic:error:。外设只会在特征值发生变化后发送通知。因此,您必须在 CBPeripheral 上调用 readValueForCharacteristic: 以获取此委托(delegate)回调中的当前值。

请注意,您通常会在 peripheral:didDiscoverCharacteristicsForService:error: 回调中获取特征值。然后您可以订阅通知,以便在特征更改其值时收到通知。

关于ios - BLE 外围设备是否会在订阅时自动发送特性值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28245090/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com