Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you create a descriptor for a mutable characteristic?

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?

like image 957
Mike Avatar asked Sep 04 '13 19:09

Mike


1 Answers

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.

like image 185
Tommy Devoy Avatar answered Oct 29 '22 16:10

Tommy Devoy