我的CoreBluetooth应用程序需要启用客户端特征配置描述符中的“指示位” . 这是我做的:
-
开始扫描
-
开始连接设备
-
致电
discoverServices
-
在回调中调用
discoverCharacteristics
-
(void)peripheral:(CBPeripheral *)peripheral diddiscoverServices:(NSError *)错误
-
在回调中调用
discoverDescriptorsForCharacteristic
-
(void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error
-
内部回调
-
(void)peripheral:(CBPeripheral *)peripheral didDiscoverDescriptorsForCharacteristic:(CBCharacteristic *)特征错误:(NSError *)错误
我打了电话:
if ( [[descriptor.UUID representativeString] isEqualToString:@"2902" ] )
{
const unsigned char raw_data[] = {0x02};
NSData *myData = [NSData dataWithBytes: raw_data length: 2];
[self.cBCP writeValue:myData forDescriptor:descriptor];
}
但我的应用程序在_1847508中崩溃了: . 控制台中的错误消息是:
无法使用此方法编写客户端特征配置描述符!
任何的想法?谢谢
2 回答
很老的问题,但由于没有回答,似乎方法
setNotifyValue(_:for:)
将为您处理,它取决于下面的charcateristics属性:仅通知:将启用通知 .
仅表示:将启用指示 .
表示并通知:仅启用通知 .
因此,如果需要启用指示,则特征必须仅具有指示属性,并且应删除通知 .
我猜这背后的主要原因是指示速度慢得多,因此iOS总是更喜欢最快的选项,除非需要指明 .
Read more on the Apple docs
问题是您不能像使用writeValue:forDescriptor:方法一样写入客户端配置描述符(UUID = 2902)的值 .
相反,您应该使用CBPeripheral类的setNotifyValue:forCharacteristic:方法来配置客户端指示或服务器上特征值的通知 .