function ab2hex(buffer) {
var hexArr = Array.prototype.map.call(
new Uint8Array(buffer),
function(bit) {
return ('00' + bit.toString(16)).slice(-2)
}
)
return hexArr.join('');
}
wx.onBluetoothDeviceFound(function(res) {
var devices = res.devices;
console.log('new device list has founded')
console.dir(devices)
console.log(ab2hex(devices[0].advertisData))
})
z这个函数有时候会报错,这事api给的实例,看log是初始化Uint8Array时,buffer的长度无效,
错误如下:
Invalid array length argument;at onBluetoothDeviceFound callback function
Uint8Array@[native code]
ab2hex@https://usr/app-service.js:1076:609
你好,看起来是onBluetoothDeviceFound回调的device对象上advertisData这个字段的长度不对;这个开发者自己先判断下长度就行;如果现在还能重现的话,麻烦再重现一次,在手机微信那里上传下日志: 我->设置->帮助与反馈右上角有个上报日志的入口,提供一下微信号,复现问题的详细时间点(如:2020-4-10 10:10)