How do you create a handle for a variable characteristic?

The documentation for CBMutableDescriptor:initWithType:value: talks about passing a "128-bit UUID that identifies the characteristic" for the type parameter. Then it should be said that for the type parameter, only one of CBUUIDCharacteristicUserDescriptionString or CBUUIDCharacteristicFormatString should be used. Finally, there is no way to add a descriptor to a mutable characteristic.

It seems that the parameter does two mutually exclusive things. On the one hand, it is used to indicate O / S to which characteristic the descriptor belongs, and on the other, the type of descriptor. The second makes more sense, but how do you add a descriptor to a characteristic?

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

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

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

+4
source share
1 answer

You are right about documents. But in order to be clear to everyone, here is a quote found in CBDescriptor.h:

... Only the characteristic description and the characteristic of the user Presently, format descriptors are supported. Characteristic advanced properties and client characteristics Configuration descriptors will be created automatically after the parent service is published, depending on the properties of the characteristic itself.

In other words, if you do not configure these descriptors, the system will block you (this is why you were denied approval).

So, say you want to use a descriptor for describing the characteristics, 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.

+4
source

Source: https://habr.com/ru/post/1500606/


All Articles