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

时间:2014-06-11 19:20:35

标签: ios7 bluetooth-lowenergy core-bluetooth

我正在尝试编写一个接收通知的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];
    }
}

为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];
    }
}

注意:第一次调用此方法时,updateValue:forCharacteristic:onSubscribedCentrals:的返回值为YES。第二次返回始终为NO

针对2个特征调用了两次PD回调

- (void)peripheral:(CBPeripheral *)peripheral didUpdateNotificationStateForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error

注意:characteristic.isNotifying始终为YES

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

返回peripheralManagerIsReadyToUpdateSubscribers:的{​​{1}}来电永远不会调用PMD回拨updateValue:forCharacteristic:onSubscribedCentrals:

NO

返回- (void)peripheralManagerIsReadyToUpdateSubscribers:(CBPeripheralManager *)peripheral 的{​​{1}}来电永远不会调用PD回调peripheral:didUpdateValueForCharacteristic:error:

updateValue:forCharacteristic:onSubscribedCentrals:

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

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

0 个答案:

没有答案