iOS Bluetooth LE cant get notification programatically but can in other apps

淺唱寂寞╮ 提交于 2019-12-11 18:37:01

问题


I'm trying to get my iOS program to communicate with a custom Bluetooth LE device. I can connect to it, read all the services, and read all the CBCharacteristic objects for each service.

I am trying to get notified when one specific CBCharacteristic is updated. The CBCharacteristic.properties is set to 0x10 (Notify) but the CBCharacteristic.isNotifying is false.

After calling the following line of code:

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

I am expecting to receive notifications via the CBPeripheralDelegate function:

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

but it never gets called.

In addition, using the LightBlue Explorer app from PunchThrough.com I CAN get notifications, so I know it is possible. What is the LightBlue app doing that I am not?

Has anyone seen something similar to this?

For reference, the device uses WLT2564M Bluetooth module. Also I can read the value using

myDevice.peripheral.readValueForCharacteristic(myChar)

without any issues.


回答1:


A few things to check:

  • the peripheral property needs to persist for the duration of its use
  • you must have connected to it (and weren't disconnected in the meantime)
  • check that the delegate is properly set
  • check logs
  • make sure you implement peripheral:didUpdateNotificationStateForCharacteristic:error: and log any errors there


来源:https://stackoverflow.com/questions/34322746/ios-bluetooth-le-cant-get-notification-programatically-but-can-in-other-apps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!