将数据从蓝牙设备转换为可读的字符串

问题描述

我从蓝牙设备获得了一系列数据,数据以字节为单位,由于我是初学者,所以我不知道如何将其设置为可读的字符串

public func peripheral(_ peripheral: CBPeripheral,didUpdateValueFor characteristic: CBCharacteristic,error: Error?) {
  let value: Data = characteristic.value!


  if let str = String(data: value,encoding: .utf8) {
     print(str)
  }

}

在控制台中,我有

p characteristic.value
(Data?) $R0 = 182 bytes

有了String(data: value,encoding: .utf8),我得到的是这样的东西:

pGrIrIpGsIqGoFoEoEoEoEoEpEpEoCoCpCqEqEqEqEqEqEpCpGpGpFpGoFoEnEnEnEnEpFpFpFpFpFpFpFqFpFpFnDm

有人可以帮助我使其可读吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)