大家好,我正在尝试使该蓝牙LE设备连接至应用程序并获取值。我正在使用Core Bluetooth,该蓝牙应能得出这些值。我有它的工作,但突然之间,它停止更新时通知值。

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对象的notify值设置为true。这意味着它更新的任何值都应调用另一个委托方法
func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?)

但是,没有调用此方法。在其中,我添加了一条打印语句以打印出每个特征,但是当我将值设置为true时,每个单个特征notify属性仍设置为NO!
peripheral did discover characteristics <CBCharacteristic: 0x1700ac0c0, UUID = 28930002-C868-423A-9DC2-E9C2FCB4EBB5, properties = 0x12, value = (null), notifying = NO>

我想念什么吗?提前致谢

最佳答案

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

10-07 12:45