didWriteValueForCharacteristic返回一个特征值作为null iOS

Zal*_*tel 5 objective-c ios core-bluetooth

我正在写数据,使用[peripheral writeValue:startFrame forCharacteristic:cbWriteCharacteristic type:CBCharacteristicWriteWithResponse];这些数据调用“ didWriteValueForCharacteristic,如下所示”

- (void)peripheral:(CBPeripheral *)peripheral didWriteValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error
{ 
    NSLog(@"characteristic.value %@",characteristic.value);
    NSLog(@"Write Data characteristic.value %@",characteristic.value);

    CBCharacteristic * cbReadCharacterstic = [self getCharacteristicWtihCBUUID:MHSW_READ_CHARACTERISTIC_ID];
    [peripheral setNotifyValue:TRUE forCharacteristic:cbReadCharacterstic];

}
Run Code Online (Sandbox Code Playgroud)

当我在did write方法中打印“ characteristic.value ”的值时,它返回null。相反,它应该提供要发送的数据的价值。当我在写方法中打印特性值时:-“ <CBCharacteristic: 0x166d0, UUID = D0F0-9DD7-7047, properties = 0x8, value = (null), notifying = NO>”值在写方法本身中显示为空。为什么会这样呢?

我该怎么办才能解决。提前致谢。

Pau*_*w11 5

呼叫didWriteValueForCharacteristic通知您带有响应的写操作已完成(即已收到响应)。它没有告诉您有关该特性的值的任何信息,因此nil是正确的值。

在执行写操作和接收响应之间,特性值可能已更改。

如果需要特征的当前值,则需要发出读取请求(或通过notify订阅值更改)。