小编use*_*208的帖子

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

我正在尝试编写一个接收通知的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 …
Run Code Online (Sandbox Code Playgroud)

core-bluetooth bluetooth-lowenergy ios7

5
推荐指数
0
解决办法
1326
查看次数

标签 统计

bluetooth-lowenergy ×1

core-bluetooth ×1

ios7 ×1