9***@qq.com
9***@qq.com
  • 发布:2023-11-29 18:38
  • 更新:2023-11-30 15:13
  • 阅读:424

【报Bug】HBuilderX 3.98版本 onBluetoothDeviceFound不执行

分类:uni-app

产品分类: uniapp/App

PC开发环境操作系统: Windows

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

HBuilderX类型: 正式

HBuilderX版本号: 3.98

手机系统: Android

手机系统版本号: Android 10

手机厂商: 华为

手机机型: 荣耀畅玩20

页面类型: vue

vue版本: vue2

打包方式: 云端

项目创建方式: HBuilderX

示例代码:

let self = this;
uni.startBluetoothDevicesDiscovery({
allowDuplicatesKey: true,
success: res => {
console.log('startBluetoothDevicesDiscovery')
setTimeout(()=>{
uni.onBluetoothDeviceFound(devices => {
console.log('onBluetoothDeviceFound')
console.log(JSON.stringify(devices))
console.log("发现新设备: " + JSON.stringify(devices));
if (devices.devices[0].name != "") {
//不重复,就添加到devicesList中,
if (!self.devicesList.some(item => {
return item.deviceId === devices.devices[0].deviceId
})) {

复制代码                                        self.devicesList.push(devices.devices[0])  
                                    }  

                                }  
                                self.devicesList.sort(function(a, b) {  
                                    if (a.deviceId === _this.connectDevice.deviceId) {  
                                        return -1;  
                                    } else if (b.deviceId === _this.connectDevice.deviceId) {  
                                        return 1;  
                                    } else {  
                                        return 0;  
                                    }  
                                })  
                            })  
                        },2000)  
                    },  
                    fail: err => {  
                        console.log(err)  
                        self.isOpenBle = false  
                        self.isSearch = false  
                        // uni.hideLoading();  
                        // bluetooth.showToast(`搜索设备失败` + JSON.stringify(err));  
                    }  
                })  

操作步骤:

let self = this;
uni.startBluetoothDevicesDiscovery({
allowDuplicatesKey: true,
success: res => {
console.log('startBluetoothDevicesDiscovery')
setTimeout(()=>{
uni.onBluetoothDeviceFound(devices => {
console.log('onBluetoothDeviceFound')
console.log(JSON.stringify(devices))
console.log("发现新设备: " + JSON.stringify(devices));
if (devices.devices[0].name != "") {
//不重复,就添加到devicesList中,
if (!self.devicesList.some(item => {
return item.deviceId === devices.devices[0].deviceId
})) {

复制代码                                        self.devicesList.push(devices.devices[0])  
                                    }  

                                }  
                                self.devicesList.sort(function(a, b) {  
                                    if (a.deviceId === _this.connectDevice.deviceId) {  
                                        return -1;  
                                    } else if (b.deviceId === _this.connectDevice.deviceId) {  
                                        return 1;  
                                    } else {  
                                        return 0;  
                                    }  
                                })  
                            })  
                        },2000)  
                    },  
                    fail: err => {  
                        console.log(err)  
                        self.isOpenBle = false  
                        self.isSearch = false  
                        // uni.hideLoading();  
                        // bluetooth.showToast(`搜索设备失败` + JSON.stringify(err));  
                    }  
                })  

预期结果:

搜索到附近蓝牙

实际结果:

未搜到附近蓝牙

bug描述:

3.96版本没问题,升级到3.98版本后uni.onBluetoothDeviceFound不执行

2023-11-29 18:38 负责人:无 分享
已邀请:
喜欢技术的前端

喜欢技术的前端 - QQ---445849201

先调用uni.openBluetoothAdapter ,再调用 uni.startBluetoothDevicesDiscovery

复制代码onReady() {  
    uni.openBluetoothAdapter({  
         success(res) {  
             console.log(res)  
        }  
    })  
},
  • 9***@qq.com (作者)

    调过了,代码没贴进去

    2023-12-01 15:24

要回复问题请先登录注册

  • 标题 / 粗斜体
  • 代码片段
  • 超链接 / 图片 / 视频
  • 列表 / 引用

文章内容较多时,可以用标题分段 :

## 大标题 
### 小标题

斜体 / 粗体 :

**粗体** 
*斜体*
***粗斜体***

代码片段 :

``` javascript
代码片段
```

超链接 :

[链接文字](链接地址) 例: [百度](http://www.baidu.com)

图片 :

![图片说明](图片地址) 例: ![百度logo](http://www.baidu.com/img/bdlogo.gif)

视频 :

!![视频说明](视频地址) 例: !![优酷视频](http://youku.com)

有序列表 :

1. 123
2. 123
3. 123

无序列表 :

- 123
- 123
- 123

引用 : ( 双回车后结束引用 )

> 引用内容
引用内容
引用内容