核心蓝牙setNotifyValue没有设置CBC特性通知属性为真

时间:2016-09-19 14:15:16

标签: ios swift bluetooth cbcentralmanager cbperipheral

嘿伙计们我试图让这个蓝牙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)")
}

}

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

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

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

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

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

1 个答案:

答案 0 :(得分:0)

您可以实施func peripheral(_ peripheral: CBPeripheral, didUpdateNotificationStateFor characteristic: CBCharacteristic, error: Error?)以查看对{​​{1}}的调用是否真正成功

相关问题