I have developed a Bluetooth Low Energy peripheral app that successfully connects with a second BLE central app. However, I am unable to get the central app to subscribe to notifications for one of the characteristics of the service offered by the peripheral. In the central app, I have the following:
- (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error
{
if ([service.UUID isEqual:[CBUUID UUIDWithString:IMMEDIATE_ALERT_SERVICE_UUID]]) {
for (CBCharacteristic *aChar in service.characteristics) {
if ([aChar.UUID isEqual:[CBUUID UUIDWithString:ALERT_LEVEL_CHARACTERISTIC_UUID]]) {
[peripheral setNotifyValue:YES forCharacteristic:aChar];
Unfortunately, this fails and an error is received at the delegate method peripheral:didUpdateNotificationStateForCharacteristic (error type is "unknown"). If I print the characteristic object in the above code (aChar), I get the following:
<CBCharacteristic: 0x1464f560, UUID = 2A06, properties = 0x2, value = (null), notifying = NO>
Notice that notifying = NO. How do I set up the peripheral to enable the characteristic to notify?
Ok, I figured it out. On the peripheral side, it is necessary to set the properties of the characteristic to enable notifications. You do this with the CBCharacteristicPropertyNotify property. For example, the following is how you might create the characteristic:
CBMutableCharacteristic *alertLevelCharacteristic =
[[CBMutableCharacteristic alloc] initWithType:alertLevelCharacteristicUUID
properties:CBCharacteristicPropertyRead | CBCharacteristicPropertyNotify
value: nil permissions:CBAttributePermissionsReadable];