核心蓝牙特征通知不起作用

use*_*208 5 core-bluetooth bluetooth-lowenergy ios7

我正在尝试编写一个接收通知的BTLE监控应用程序.我使用Core Bluetooth(在iOS 7.1上)构建了中央应用程序和模拟外围应用程序.我的中心可以很好地连接到外围设备,它宣传具有2个CBCharacteristicPropertyNotify特征的服务.但是,一旦中心发现了这些特征(为了清晰起见,删除了非必要的代码),就会发生这种情况.

PD = CBPeripheralDelegate在中央

PMD =外围设备中的CBPeripheralManagerDelegate

调用PD回调

- (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error
{
    for (CBCharacteristic *characteristic in service.characteristics)
    {
        [peripheral setNotifyValue:YES forCharacteristic:characteristic];
    }
}
Run Code Online (Sandbox Code Playgroud)

对于2个特征,PMD回调被调用两次

- (void)peripheralManager:(CBPeripheralManager *)peripheral central:(CBCentral *)central didSubscribeToCharacteristic:(CBCharacteristic *)characteristic
{
    if ([characteristic.UUID isEqual:[CBUUID UUIDWithString:FILTER_GENUINE_CHARACTERISTIC_UUID]])
    {
        BOOL genuineSent = [self.peripheralManager updateValue:genuineValue
                                                     forCharacteristic:self.filterGenuineCharacteristic
                                                  onSubscribedCentrals:nil];
    }
    else if ([characteristic.UUID isEqual:[CBUUID UUIDWithString:FILTER_LOADING_CHARACTERISTIC_UUID]])
    {
        BOOL loadingSent = [self.peripheralManager updateValue:loadingValue
                                                     forCharacteristic:self.filterLoadingCharacteristic
                                                  onSubscribedCentrals:nil];
    }
}
Run Code Online (Sandbox Code Playgroud)

注:第一次调用此方法返回的updateValue:forCharacteristic:onSubscribedCentrals:YES.第二次总是回归NO.

PD回调为2个特征调用了两次

- (void)peripheral:(CBPeripheral *)peripheral didUpdateNotificationStateForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error
Run Code Online (Sandbox Code Playgroud)

注意:characteristic.isNotifying总是YES.

但就是这样,没有其他回调方法被调用!

peripheralManagerIsReadyToUpdateSubscribers:永远不会为updateValue:forCharacteristic:onSubscribedCentrals:返回的调用调用PMD回调NO

- (void)peripheralManagerIsReadyToUpdateSubscribers:(CBPeripheralManager *)peripheral
Run Code Online (Sandbox Code Playgroud)

peripheral:didUpdateValueForCharacteristic:error:永远不会为updateValue:forCharacteristic:onSubscribedCentrals:返回的调用调用PD回调YES

- (void)peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error
Run Code Online (Sandbox Code Playgroud)

我一直在运行iOS 7.1的iPad Air和iPhone 5s上测试这些应用程序.

知道为什么永远不会调用通知吗?