uni-app
uni-app copied to clipboard
uni.onBluetoothAdapterStateChange 返回值错误
trafficstars
发行方式
None
具体平台
android 12
开发环境
macOS
项目创建方式
HBuilderX
依赖版本
HBuilder X: 4.57
问题描述
uni.onBluetoothAdapterStateChange 返回值错误
重现步骤
复现方式一
- 调用 uni.openBluetoothAdapter()
- 调用 uni.onBluetoothAdapterStateChange(), 监听蓝牙状态
- 调用 uni.startBluetoothDevicesDiscovery(), 开始探索设备
- 关闭系统蓝牙, 此时 uni.onBluetoothAdapterStateChange() 返回 {available: false, discovering: true}
- 打开系统蓝牙, 此时 uni.onBluetoothAdapterStateChange() 返回 {available: true, discovering: true}
复现方式二
- 调用 uni.openBluetoothAdapter()
- 调用 uni.onBluetoothAdapterStateChange(), 监听蓝牙状态
- 调用 uni.startBluetoothDevicesDiscovery()
- 关闭系统蓝牙, 此时 uni.onBluetoothAdapterStateChange(), 返回 {available: false, discovering: true}
- uni.stopBluetoothDevicesDiscovery() 此时 uni.onBluetoothAdapterStateChange(), 返回 {available: true, discovering: false}
期望行为
uni.onBluetoothAdapterStateChange() 与实际蓝牙/探索状态相同
实际行为
从表现来看 uni.onBluetoothAdapterStateChange() 的返回值 available 和 discovering 是根据调用蓝牙方法来标记的, 并不是根据实际状态来标记的
如果为解决"复现方式一"中第4步的问题, 在 uni.onBluetoothAdapterStateChange() 手动处理返回值并调用 uni.stopBluetoothDevicesDiscovery(), 则会出现"复现方式二"
截图或录屏
No response