收藏
回答

writeBLECharacteristicValue不可以写入Uint8Array?

找到的str转buffer的方法如下
export const str2buffer = (str: string): ArrayBuffer => {
  return new Uint8Array(
    unescape(encodeURIComponent(str)).split("").map((value) => {
      return value.charCodeAt(0)
    })
  )
}


通过这个方法生成数据后,直接调用

wx.writeBLECharacteristicValue({
      deviceId: this.data.deviceId,
      serviceId: this.data.serviceId,
      characteristicId,
      value: str2buffer("123"),
      success: (res) => {
        
      }
    })


提示我

{"errno":1001,"errMsg":"writeBLECharacteristicValue:fail parameter error: parameter.value should be ArrayBuffer instead of Uint8Array;"}


我用的ts,好奇为啥不能Uint8Array


回答关注问题邀请回答
收藏

1 个回答

登录 后发表内容