我开发了一个蓝牙低功耗外围应用程序,它成功连接了第二个 BLE 中央应用程序。但是,我无法让中央应用程序订阅有关外围设备提供的服务特征之一的通知。在中央应用程序中,我有以下内容:
- (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error
{
if ([service.UUID isEqual:[CBUUID UUIDWithString:IMMEDIATE_ALERT_SERVICE_UUID]]) {
for (CBCharacteristic *aChar in service.characteristics) {
if ([aChar.UUID isEqual:[CBUUID UUIDWithString:ALERT_LEVEL_CHARACTERISTIC_UUID]]) {
[peripheral setNotifyValue:YES forCharacteristic:aChar];
不幸的是,这失败了,并且在委托方法 peripheral:didUpdateNotificationStateForCharacteristic 收到了错误(错误类型为“未知”)。如果我在上面的代码(aChar)中打印特征对象,我会得到以下信息:
<CBCharacteristic: 0x1464f560, UUID = 2A06, properties = 0x2, value = (null), notifying = NO>
请注意,通知 = 否。如何设置外围设备以启用特性通知?