6***@qq.com
6***@qq.com
  • 发布:2024-06-06 15:15
  • 更新:2024-06-06 16:09
  • 阅读:118

【报Bug】安卓执行closeBLEConnection,连接实例一直存在

分类:uni-app

产品分类: uniapp/App

PC开发环境操作系统: Windows

PC开发环境操作系统版本号: win10

HBuilderX类型: 正式

HBuilderX版本号: 4.15

手机系统: Android

手机系统版本号: Android 9.0

手机厂商: 华为

手机机型: Honor 8A

页面类型: vue

vue版本: vue3

打包方式: 离线

项目创建方式: HBuilderX

示例代码:

closeBLEConnection() {
let that = this
console.log("closeBLEConnection:",this.globalData.ble_device.mac)
uni.closeBLEConnection({
deviceId: this.globalData.ble_device.mac,
success(res) {
console.log("closeBLEConnection:")
console.log(res)
setTimeout(() => {
that.closeBluetoothAdapter()
uni.$emit('close_ble', null)
}, 1000);
that.initBle()
}
})
},
createBLEConnection(device) {
let that = this
console.log("#####################################@@@@@@@@@@@@@")
uni.createBLEConnection({
deviceId: device.mac,
success: (res) => {
that.globalData.ble_device = device
setTimeout(() => {
uni.onBLEConnectionStateChange(function (res) {
// 该方法回调中可以用于处理连接意外断开等异常情况
if (!res.connected) {
that.showInfo("设备已断开,请重连")
// that.initBle()
// that.createBLEConnection(device)
}
console.log(device ${res.deviceId} state has changed, connected: ${res.connected})
})
// that.getBLEDeviceServices(device.mac)
}, 2000);
},
fail: (res) => {
uni.hideLoading()
}
})
},

操作步骤:

按钮执行createBLEConnection成功后,接着按钮执行closeBLEConnection,反复操作2次以上。
onBLEConnectionStateChange会执行2次以上。

预期结果:

执行closeBLEConnectionon后,BLEConnectionStateChange会执行一次。

实际结果:

按钮执行createBLEConnection成功后,接着按钮执行closeBLEConnection,反复操作2次以上。
onBLEConnectionStateChange会执行2次以上。

bug描述:

按钮执行createBLEConnection成功后,接着按钮执行closeBLEConnection,反复操作。
onBLEConnectionStateChange会执行多次。

2024-06-06 15:15 负责人:无 分享
已邀请:
6***@qq.com

6***@qq.com (作者)

已解决
核心问题不能多次监听
比如:uni.onBLEConnectionStateChange,uni.onBLEConnectionStateChange
不能多次调用监听
加上一个判断,已调用过就不用调用

要回复问题请先登录注册