用户2847172
用户2847172
  • 发布:2025-07-01 11:24
  • 更新:2025-07-01 15:36
  • 阅读:33

蓝牙搜索,返回的数据中,advertisData 为什么 一直是 “” 或者 { } , 没有数据呢?iOS和Android都是如此

分类:uni-app

这个是搜索的代码
uni.startBluetoothDevicesDiscovery({
allowDuplicatesKey: true,
interval: 0,
success(res) {
},
fail(err) {
},
});

监听搜索到的设备,uni.onBluetoothDeviceFound

日志

{"RSSI":-29,"advertisData":"","deviceId":"B8C8889D-F747-BF14-C1C4-75608CD3466C","localName":"MTLink_rlzgqz_Ux","name":"nimble"}
{"RSSI":-29,"advertisData":{},"deviceId":"B8C8889D-F747-BF14-C1C4-75608CD3466C","localName":"MTLink_rlzgqz_Ux","name":"nimble"}

2025-07-01 11:24 负责人:无 分享
已邀请:
qjr

qjr

直接打印advertisData是不行的,试试官方的方法再打印看看

function ab2hex(buffer) {  
  const hexArr = Array.prototype.map.call(  
    new Uint8Array(buffer),  
    function (bit) {  
      return ('00' + bit.toString(16)).slice(-2)  
    }  
  )  
  return hexArr.join('')  
}  
uni.onBluetoothDeviceFound(function (devices) {  
  console.log('new device list has founded')  
  console.dir(devices)  
  console.log(ab2hex(devices[0].advertisData))  
})

要回复问题请先登录注册