I am attempting to use CoreBluetooth to write to a specific, known characteristic. I feel this should be possible as I have used a Texas Instruments BLE utility that you can select a "write value" action on a connected peripheral and simply enter the characteristic UUID and the value you want written and it executes no problem.
By my understanding, in order to do this I have to make a call to
[peripheral writeValue:data forCharacteristic:...];
with a CBCharacteristic
object configured to have the correct UUID.
I have tried making a CBMutableCharacteristic
with the correct UUID, and even correct permissions for what I know is an existing characteristic in this peripheral's profile, and I get the following crash, when attempting to perform any read/write operation with that characteristic on the peripheral:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CBMutableCharacteristic peripheral]: unrecognized selector sent to instance 0x1ed57690'
And here is the code I use to set up and write to the characteristic:
NSString *characteristicUUIDstring = @"fff1";
CBUUID *characteristicUUID = [CBUUID UUIDWithString:characteristicUUIDstring];
char dataByte = 0x10;
NSData *data = [NSData dataWithBytes:&dataByte length:1];
CBMutableCharacteristic *testCharacteristic = [[CBMutableCharacteristic alloc] initWithType:characteristicUUID properties:CBCharacteristicPropertyRead|CBCharacteristicPropertyWrite value:data permissions:CBAttributePermissionsReadable|CBAttributePermissionsWriteable];
[peripheral writeValue:data forCharacteristic:testCharacteristic type:CBCharacteristicWriteWithResponse];