【问题标题】:Core Bluetooth setNotifyValue isn't setting CBCharacteristics notifying property to true核心蓝牙 setNotifyValue 未将 CBCharacteristics 通知属性设置为 true
【发布时间】:2017-01-27 06:33:05
【问题描述】:

大家好,我正在尝试让这个蓝牙 LE 设备连接到应用程序并获取值。我正在使用核心蓝牙,它应该可以输出值。我让它工作但突然间它在更新时停止通知值。

func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?) {
for characteristic in service.characteristics! {
  peripheral.setNotifyValue(true, for: characteristic)
  print("peripheral did discover characteristics \(characteristic)")
}

}

在委托方法调用中,我将每个 CBCharacteristic 对象的通知值设置为 true。这应该意味着它更新的任何值都应该调用另一个委托方法

func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?)

但是这个方法没有被调用。在我添加了一个打印语句来打印出每个特性,但是当我将值设置为 true 时,每个单个特性的通知属性仍然设置为 NO!

peripheral did discover characteristics <CBCharacteristic: 0x1700ac0c0, UUID = 28930002-C868-423A-9DC2-E9C2FCB4EBB5, properties = 0x12, value = (null), notifying = NO>

我错过了什么吗?提前致谢

【问题讨论】:

  • 您是否检查了特性的属性以确保支持通知?
  • 我是 Core Bluetooth 的新手,我认为这不可能!我这样做了,有趣的是,除非我有这个设备的应用程序并且它使用该应用程序配对,否则不支持通知。现在它可以得到通知。太感谢了!我从你告诉我这件事中学到了很多!!!

标签: ios swift bluetooth cbcentralmanager cbperipheral


【解决方案1】:

您可以实现func peripheral(_ peripheral: CBPeripheral, didUpdateNotificationStateFor characteristic: CBCharacteristic, error: Error?) 来查看对setNotifyValue(_:for:) 的调用是否真的成功

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-26
    • 2016-08-17
    • 1970-01-01
    • 2022-01-07
    • 1970-01-01
    • 2014-11-25
    • 1970-01-01
    相关资源
    最近更新 更多