【问题标题】:Corebluetooth write Hexadecimal Value for CharacteristicCorebluetooth 为特征写入十六进制值
【发布时间】:2015-11-13 13:55:19
【问题描述】:

我正在尝试在调用 didDiscoverCharacteristicsForService 方法时为特征写入十六进制值 NSString * const SET_BUZZER_ON = @"0xef";,然后检查我是否处于正确的特征中:

NSData* valData = [self dataFromHexString:SET_BUZZER_ON];
[aPeripheral writeValue:valData forCharacteristic:aChar type:CBCharacteristicWriteWithResponse];

代码执行没有问题,但是当方法didWriteValueForCharacteristic被调用时,我得到了错误:

Error writing characteristic value: The value's length is invalid.

有什么想法吗?

【问题讨论】:

    标签: ios hex core-bluetooth


    【解决方案1】:

    我刚刚想通了,我必须用Bytes Array 而不是NSString 来初始化NSData

    const uint8_t bytes[] = {0xef};
    NSData *valData = [NSData dataWithBytes:bytes length:sizeof(bytes)];
    

    【讨论】:

      猜你喜欢
      • 2011-06-25
      • 1970-01-01
      • 1970-01-01
      • 2015-08-22
      • 2011-12-22
      • 1970-01-01
      • 1970-01-01
      • 2018-07-26
      • 1970-01-01
      相关资源
      最近更新 更多