dcloudio / dcloudio/native-docs

uni.onBluetoothAdapterStateChange回调两次

Open
#129 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
88
Forks
75
PR merge metrics
No merged PRs in 30d

Description

**问题描述**
[问题描述:尽可能简洁清晰地把问题描述清楚]
试图使用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()
}
}
})

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.