How to enable pointers to a client configuration descriptor from iOS8

I am trying to get a notification from a bluetooth device when the feature value changes. To do this, I need to enable notification for the client characteristics configuration descriptor (CCC). I used setNotifyValue(enabled: Bool, forCharacteristic characteristic: CBCharacteristic) for the characteristic, but did not receive an update to change the values.

I tried to enable writeValue(data: NSData, forDescriptor descriptor: CBDescriptor) for CCC using writeValue(data: NSData, forDescriptor descriptor: CBDescriptor) , but my application crashes for this API and shows an error like

It is not possible to write descriptive descriptors for client configuration using this method!

Any help!

+7
ios iphone swift bluetooth bluetooth-lowenergy
source share
1 answer

Providing more codes can help improve the accuracy of the response; however, suppose that you have already been able to detect all the characteristic values. Usually you just need to CBPeripheralDelegate over all the characteristics and set / write the value according to each client configuration descriptor (CCC) in the CBPeripheralDelegate implementation.

An example is given below:

 - (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error { if (error) { NSLog(@"Error discovering characteristics: %@", error); return; } for (CBCharacteristic *characteristic in service.characteristics) { if ([characteristic.UUID isEqual:[CBManager accelDataUUID]]) { [peripheral setNotifyValue:YES forCharacteristic:characteristic]; } else if ([characteristic.UUID isEqual:[CBManager accelConfigUUID]]) { [peripheral writeValue:[CBManager switchData:YES] forCharacteristic:characteristic type:CBCharacteristicWriteWithResponse]; } //... if you have more to iterate } } 
+1
source share

All Articles