简体   繁体   中英

Implementing read/write characteristic in the CoreBluetooth.framework

I am working on the corebluetooth framework currently I have created the peripheral with the writable and readable characteristic . Its working fine for me . But I want to create read- write peripheral .I have tried following :

characteristic = [[CBMutableCharacteristic alloc] initWithType:characteristicUUID
                                                                  properties:(CBCharacteristicPropertyRead|CBCharacteristicPropertyWrite)
                                                                       value:nil
                                                                 permissions:(CBAttributePermissionsWriteable|CBAttributePermissionsReadable)];

but its not working in above case also the property is either readable or writable not both at a time .I think it is taking the first one . am I missing anything ?

A couple things that you should check:

  1. Make sure that when you use the method - (void)writeValue:(NSData *)data forCharacteristic:(CBCharacteristic *)characteristic type:(CBCharacteristicWriteType)type , the CBCharacteristicWriteType you use should match the CBCharacteristic properties.

  2. In your peripheral implementation,

- (void)peripheralManager:(CBPeripheralManager *)peripheral didReceiveWriteRequests:(NSArray *)requests ,

make sure you don't have this gem in there: `

[peripheral respondToRequest:request withResult:CBATTErrorWriteNotPermitted];

I copied that from the CoreBluetooth Programming Guide, and it messed me up for a full hour.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM