MindSpiker
MindSpiker

Reputation: 1464

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

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.

Upvotes: 0

Views: 332

Answers (1)

jcaron
jcaron

Reputation: 17710

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

Upvotes: 1

Related Questions