5

The documentation for CBMutableDescriptor:initWithType:value: says to pass a "128-bit UUID that identifies the characteristic" for the type parameter. It then goes on to say you should only use one of CBUUIDCharacteristicUserDescriptionString or CBUUIDCharacteristicFormatString for the type parameter. Finally, there is no method to add a descriptor to a mutable characteristic.

It appears that the parameter is doing two mutually exclusive things. On the one hand, it is being used to tell the O/S which characteristic the descriptor applies to, and on the other, it is being used to set the type of descriptor. The second makes more sense, but then how do you add the descriptor to the characteristic?

Whether you pass the UUID for the characteristic or CBUUIDCharacteristicUserDescriptionString, iOS crashes with

Assertion failure in -[CBMutableDescriptor initWithType:value:], /SourceCache/CoreBluetooth_Sim/CoreBluetooth-59.3/CBDescriptor.m:25

What's the correct way to create the CBMutableDescriptor and add it to a CBMutableCharacteristic?

1 Answer 1

5

You're correct about the docs. But just to be clear for everyone, here is a citation found in CBDescriptor.h:

...Only the Characteristic User Description and Characteristic Presentation Format descriptors are currently supported. The Characteristic Extended Properties and Client Characteristic Configuration descriptors will be created automatically upon publication of the parent service, depending on the properties of the characteristic itself.

So in other words, unless you are setting those descriptors, the system will block you (thus why you got the assertion failure).

So say you want to use the Characteristic User Description descriptor, you would do:

CBUUID *yourCharUUID = [CBUUID UUIDWithString:@"c07c5050-15a0-11e3-8ffd-0800200c9a66"];//whatever UUID your using

CBMutableCharacteristic *yourCharacteristic = [[CBMutableCharacteristic alloc]initWithType:yourCharUUID properties:CBCharacteristicPropertyWriteWithoutResponse value:nil permissions:perms];

CBUUID *userDescriptionUUID = [CBUUID UUIDWithString:CBUUIDCharacteristicUserDescriptionString];//or set it to the actual UUID->2901

CBMutableDescriptor *yourDescriptor = [[CBMutableDescriptor alloc]initWithType:userDescriptionUUID value:@"myDescriptorValue"];

yourCharacteristic.descriptors = @[yourDescriptor];

Let me know if you have any questions.

1
  • Hi, Is there any option for Custom CBDescriptor to enable with sending values?
    – Hari c
    Oct 6, 2017 at 14:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.