我正在使用核心蓝牙。我添加了在特性上写入/读取的功能。在此之前,我想检查特征是否可写。我为此目的使用了characteristic.properties,我的代码是:
if (characteristic.properties==CBCharacteristicPropertyRead)
{
[peripheralDevice readValueForCharacteristic:characteristic];
}
else if(characteristic.properties==CBCharacteristicPropertyWrite)
{
[peripheralDevice setNotifyValue:YES forCharacteristic:characteristic];
}
NSLog(@"the property :%d",currentCharacteristic.properties );
这是文档中 Characteristic.properties 的枚举:
typedef NS_ENUM(NSInteger, CBCharacteristicProperties) {
CBCharacteristicPropertyBroadcast = 0x01,
CBCharacteristicPropertyRead = 0x02,
CBCharacteristicPropertyWriteWithoutResponse = 0x04,
CBCharacteristicPropertyWrite = 0x08,
CBCharacteristicPropertyNotify = 0x10,
CBCharacteristicPropertyIndicate = 0x20,
CBCharacteristicPropertyAuthenticatedSignedWrites = 0x40,
CBCharacteristicPropertyExtendedProperties = 0x80,
CBCharacteristicPropertyNotifyEncryptionRequired NS_ENUM_AVAILABLE(NA, 6_0) = 0x100,
CBCharacteristicPropertyIndicateEncryptionRequired NS_ENUM_AVAILABLE(NA, 6_0) = 0x200
};
它可以很好地从特征中读取值。但问题是在写入值时它不会进入第二个循环。我已经用可写属性设置了特性。我得到了我检查过的两个外围设备的 136 in print 语句。请提出一些解决方案来克服这个问题?