gpt4 book ai didi

iOS Bluetooth LE 无法以编程方式获取通知,但可以在其他应用程序中获取通知

转载 作者:行者123 更新时间:2023-11-29 01:23:27 24 4
gpt4 key购买 nike

我正在尝试让我的 iOS 程序与自定义蓝牙 LE 设备进行通信。我可以连接到它,读取所有服务,并读取每个服务的所有 CBCharacteristic 对象。

当一个特定的 CBCharacteristic 更新时,我试图收到通知。 CBCharacteristic.properties 设置为 0x10(通知),但 CBCharacteristic.isNotifying 为 false。

调用以下代码行后:

myDevice.peripheral.setNotifyValue(true, forCharacteristic: myChar)

我希望通过 CBPeripheralDelegate 函数接收通知:

func peripheral(peripheral: CBPeripheral, didUpdateValueForCharacteristic characteristic: CBCharacteristic, error: NSError?) {}

但它永远不会被调用。

此外,使用 LightBlue Explorer app来自PunchThrough.com我可以收到通知,所以我知道这是可能的。 LightBlue 应用程序在做什么而我没有做什么?

有人见过类似的东西吗?

作为引用,该设备使用 WLT2564M蓝牙模块。我也可以使用

读取值
myDevice.peripheral.readValueForCharacteristic(myChar)

没有任何问题。

最佳答案

需要检查的几件事:

  • peripheral 属性需要在其使用期间持续存在
  • 您一定已经连接到它(同时没有断开连接)
  • 检查 delegate 是否设置正确
  • 检查日志
  • 确保你实现了 peripheral:didUpdateNotificationStateForCharacteristic:error: 并在那里记录任何错误

关于iOS Bluetooth LE 无法以编程方式获取通知,但可以在其他应用程序中获取通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34322746/

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