My CoreBluetooth application need to enable the "indication bit" in Client Characteristic Configuration descriptors. Here is what I did:
discoverServices
Call discoverCharacteristics
inside the callback
-(void)peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)error
Call discoverDescriptorsForCharacteristic
inside callback
-(void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error
Inside callback
-(void)peripheral:(CBPeripheral *)peripheral didDiscoverDescriptorsForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error
I called:
if ( [[descriptor.UUID representativeString] isEqualToString:@"2902" ] )
{
const unsigned char raw_data[] = {0x02};
NSData *myData = [NSData dataWithBytes: raw_data length: 2];
[self.cBCP writeValue:myData forDescriptor:descriptor];
}
But My app crashes in writeVale
: . The error message in console is :
Cannot write Client Characteristic Configuration descriptors using this method!
Any idea? Thanks
Pretty old question, but since it wasn't answered, seems like if the method setNotifyValue(_:for:)
will handle that for you, it depends on the charcateristics properties below:
So if you need to enable indications, the characteristic must only have the indicate property, and notify should be removed.
I guess the main reasoning behind that is indications are much slower, so iOS will always prefer the fastest possible option unless it's a requirement to indicate.
Read more on the Apple docs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With