native-docs icon indicating copy to clipboard operation
native-docs copied to clipboard

uni.onBluetoothAdapterStateChange回调两次

Open zhangchenzhuo opened this issue 2 years ago • 0 comments

问题描述 [问题描述:尽可能简洁清晰地把问题描述清楚] 试图使用uni.onBluetoothAdapterStateChange方法来判断蓝牙是否开启,但是开关系统蓝牙会回调两次这个方法。第一次并不准确,第二次才是准确的 复现步骤 [复现问题的步骤]

  1. 启动 '....'
  2. 点击 '关闭系统蓝牙,回调两次,开启系统蓝牙,回调两次'
  3. 查看

[或者可以直接贴源代码]

预期结果 [使用简洁清晰的语言描述你希望生效的预期结果] 回调一次 实际结果 [这里请贴上你的报错截图或文字] 回调两次 关闭 15:58:16.611 [Object] {"discovering":false,"available":false} at pages/index/index.vue:81 15:58:16.700 [Object] {"discovering":false,"available":false} at pages/index/index.vue:81 开启 15:58:21.788 [Object] {"discovering":false,"available":false} at pages/index/index.vue:81 15:58:21.973 [Object] {"discovering":false,"available":true} at pages/index/index.vue:81

系统信息:

  • 发行平台: app
  • 操作系统 [Android 9.0]
  • HBuilderX版本 [HBuilderX,3.4.7.20220422]
  • uni-app版本 [Vue3.0, uniapp 13.4.7]
  • 设备信息 [AUTOID pad air]

补充信息 https://github.com/dcloudio/uni-app/issues/958 已经修改,但是问题依旧出现 源码: uni.onBluetoothAdapterStateChange((result)=>{ console.log(result); if (result.available == true) { _this.bleAdapterAvailable = true; } else { _this.bleAdapterAvailable = false; if (result.discovering) { _this.stopScan() } } })

zhangchenzhuo avatar May 13 '22 08:05 zhangchenzhuo