How to initialize a CBMutableCharacteristic with multiple CBCharacteristicProperties and Permissions

大城市里の小女人 提交于 2019-12-23 07:37:49

问题


I'm creating a new CBMutableCharacteristic for use in a Bluetooth app I'm making. I got some code from a tutorial, which looks like this:

_customCharacteristic = [[CBMutableCharacteristic alloc] initWithType:characteristicUUID properties:CBCharacteristicPropertyNotify value:nil permissions:CBAttributePermissionsReadable];

where _customCharacteristic is my CBMutableCharacteristic.

However, I want to initialize my _customCharacteristic with other properties, such as CBCharacteristicPropertyRead and CBCharacteristicPropertyWrite. The same is true for the permissions: I want to also give it CBAttributePermissionsWriteable.

According to this: http://developer.apple.com/library/ios/#documentation/CoreBluetooth/Reference/CBCharacteristic_Class/translated_content/CBCharacteristic.html#//apple_ref/doc/c_ref/CBCharacteristicProperties

and this: http://developer.apple.com/library/ios/#documentation/CoreBluetooth/Reference/CBMutableCharacteristic_Class/Reference/CBMutableCharacteristic.html#//apple_ref/doc/c_ref/CBAttributePermissions

I can have both multiple properties and permissions for each characteristic. However, I don't know how to initialize my CBMutableCharacteristic in this way.


回答1:


Its an enum, whose different values can be ORed bitwisely, so you can use the characteristic properties and permissions together:

CBMutableCharacteristic *_customCharacteristic = [[CBMutableCharacteristic alloc] initWithType:characteristicUUID properties:CBCharacteristicPropertyNotify+CBCharacteristicPropertyRead
 value:nil permissions:CBAttributePermissionsReadable|CBAttributePermissionsWriteable];



回答2:


tdevoy answer is right one , Or following is also working code for me

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


来源:https://stackoverflow.com/questions/18114121/how-to-initialize-a-cbmutablecharacteristic-with-multiple-cbcharacteristicproper

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!