uni-app icon indicating copy to clipboard operation
uni-app copied to clipboard

uni.onBluetoothAdapterStateChange 返回值错误

Open songlingxi opened this issue 6 months ago • 0 comments
trafficstars

发行方式

None

具体平台

android 12

开发环境

macOS

项目创建方式

HBuilderX

依赖版本

HBuilder X: 4.57

问题描述

uni.onBluetoothAdapterStateChange 返回值错误

重现步骤

复现方式一

  1. 调用 uni.openBluetoothAdapter()
  2. 调用 uni.onBluetoothAdapterStateChange(), 监听蓝牙状态
  3. 调用 uni.startBluetoothDevicesDiscovery(), 开始探索设备
  4. 关闭系统蓝牙, 此时 uni.onBluetoothAdapterStateChange() 返回 {available: false, discovering: true}
  5. 打开系统蓝牙, 此时 uni.onBluetoothAdapterStateChange() 返回 {available: true, discovering: true}

复现方式二

  1. 调用 uni.openBluetoothAdapter()
  2. 调用 uni.onBluetoothAdapterStateChange(), 监听蓝牙状态
  3. 调用 uni.startBluetoothDevicesDiscovery()
  4. 关闭系统蓝牙, 此时 uni.onBluetoothAdapterStateChange(), 返回 {available: false, discovering: true}
  5. uni.stopBluetoothDevicesDiscovery() 此时 uni.onBluetoothAdapterStateChange(), 返回 {available: true, discovering: false}

期望行为

uni.onBluetoothAdapterStateChange() 与实际蓝牙/探索状态相同

实际行为

从表现来看 uni.onBluetoothAdapterStateChange() 的返回值 available 和 discovering 是根据调用蓝牙方法来标记的, 并不是根据实际状态来标记的

如果为解决"复现方式一"中第4步的问题, 在 uni.onBluetoothAdapterStateChange() 手动处理返回值并调用 uni.stopBluetoothDevicesDiscovery(), 则会出现"复现方式二"

截图或录屏

No response

songlingxi avatar May 19 '25 02:05 songlingxi