恍恍惚惚呼呼呼
恍恍惚惚呼呼呼
  • 发布:2023-06-14 11:51
  • 更新:2024-07-08 11:42
  • 阅读:1007

【报Bug】IOSApp 16.5版本下获取 uni.getBluetoothDevices获取蓝牙设备 advertisData参数没有数据

分类:uni-app

产品分类: uniapp/App

PC开发环境操作系统: Windows

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

HBuilderX类型: 正式

HBuilderX版本号: 3.8.4

手机系统: iOS

手机系统版本号: iOS 16

手机厂商: 苹果

手机机型: iphone14

页面类型: vue

vue版本: vue2

打包方式: 云端

项目创建方式: HBuilderX

操作步骤:
  1. 生成自定义基座IOS APP
  2. 按正常低功耗蓝牙步骤,走到uni.getBluetoothDevices 获取蓝牙设备
  3. 获取到设备中的advertisData数据

预期结果:

advertisData中数据为arrayBuffer

实际结果:

advertisData中数据空

bug描述:

IOS App 中获取低功耗蓝牙设备,返回设备信息中advertisData字段数据是空

2023-06-14 11:51 负责人:无 分享
已邀请:
DCloud_iOS_WZT

DCloud_iOS_WZT

startBluetoothDevicesDiscovery 时设置参数 allowDuplicatesKey: true
advertisData 首先不一定所有设备都有 其次首次不一定获取得到 需要配 allowDuplicatesKey: true 看后面能不能检索到

  • 恍恍惚惚呼呼呼 (作者)

    allowDuplicatesKey: true这个确定已经开启,搜索的蓝牙设备是我们自己生产的同一个设备;在低版本的ios上都是能搜到的,更新到16.5后就没有了

    2023-06-14 17:37

  • DCloud_iOS_WZT

    回复 恍恍惚惚呼呼呼: 代码发一下,重复获取的设备你是怎么处理的 只取第一次的还是会覆盖

    2023-06-14 18:16

  • DCloud_iOS_WZT

    回复 恍恍惚惚呼呼呼: 你可以打印一下onBluetoothDeviceFound 这个回调的信息 看后面是不是获取到了

    2023-06-14 18:19

  • 恍恍惚惚呼呼呼 (作者)

    回复 DCloud_iOS_WZT:代码评论在下面了,我就是在onBluetoothDeviceFound 这个事件里循环取的。

    2023-06-15 15:18

  • DCloud_iOS_WZT

    回复 恍恍惚惚呼呼呼: allowDuplicatesKey: true 然后你再 onBluetoothDeviceFound 里的devices打印出来看看有没有有数据的

    2023-06-15 16:21

  • 恍恍惚惚呼呼呼 (作者)

    可以了,第一次的时候没有,但是后面有了。那请问什么情况下走这个方法getBluetoothDevices,什么情况下用这个呢onBluetoothDeviceFound?因为这个getBluetoothDevices里面是一直没有的

    2023-06-15 17:05

  • DCloud_iOS_WZT

    回复 恍恍惚惚呼呼呼: 这个没有明确的要求 你可以直接用onBluetoothDeviceFound 自己去记录 getBluetoothDevices就是onBluetoothDeviceFound首次的记录

    2023-06-15 18:04

恍恍惚惚呼呼呼

恍恍惚惚呼呼呼 (作者) - 阿达

startBluetoothDevicesDiscovery() {
// uni.showToast({
// title: '正在连接蓝牙',
// icon: 'loading',
// duration: 99999
// });
uni.startBluetoothDevicesDiscovery({
success: e => {
console.log('开始搜索蓝牙设备:' + e.errMsg);
uni.onBluetoothDeviceFound(devices => {
this.getBluetoothDevices();
});
},
fail: e => {
console.log('搜索蓝牙设备失败,错误码:' + e.errCode);
if (e.errCode !== 0) {
this.initTypes(e.errCode);
}
}
});
},
getBluetoothDevices() {
let that = this;
uni.getBluetoothDevices({
success: res => {
console.log('---------------获取蓝牙设备成功:' + res.errMsg + "----------");

                    res.devices.forEach(item => {  
                        if (this.deviceId == 0) {   
                            console.log("name" + item.name);   
                            let actMacAddr = ab2hex(item.advertisData).toUpperCase();  
                            console.log('-------------------macaddr:' + actMacAddr + '---------');  
                            //if (item.name == this.equName) {  
                                if (actMacAddr == that.equName) {  
                                this.deviceId = item.deviceId;  
                                this.macaddr = ab2hex(item.advertisData);  
                                uni.createBLEConnection({  
                                    // 这里的 deviceId 需要已经通过 createBLEConnection 与对应设备建立链接  
                                    deviceId: this.deviceId,  
                                    success: res => {  
                                        console.log('连接蓝牙成功:' + res.errMsg);  
                                        that.isConnect = true;  
                                        uni.setBLEMTU({  
                                            deviceId: item.deviceId,  
                                            mtu: 500  
                                        })  
                                        // 连接设备后断开搜索 并且不能搜索设备  
                                        this.stopBluetoothDevicesDiscovery(true);   

                                    },  
                                    fail: e => {  
                                        console.log('连接低功耗蓝牙失败,错误码:' + e.errCode);  
                                        that.disconnect();  
                                        if (e.errCode !== 0) {  
                                            this.initTypes(e.errCode);  
                                        }  
                                    }  
                                });  

                            }  
                        }  

                    })  
                },  
                fail: e => {  
                    console.log('获取蓝牙设备错误,错误码:' + e.errCode);  
                    if (e.errCode !== 0) {  
                        this.initTypes(e.errCode);  
                    }  
                }  
            });  
        },
Mkit

Mkit - 那就这样吧

ipadOS17 发现返回advertisData是空字符串,其他设备返回时arraybuffer,allowDuplicatesKey: true尝试没有用啊。

  • 3***@qq.com

    哥,这个问题有解决吗,我正在这个坑里躺着呢。

    2023-07-29 15:48

  • Mkit

    回复 3***@qq.com: allowDuplicatesKey: true,确实可以让同一台设备多次返回,当返回第二次的时候就有advertisData值。但需要注意的是,它是通过onBluetoothDeviceFound回调函数一台一台返回才有,所以我这边做法是废弃getBluetoothDevices一次获取设备列表的操作,改用onBluetoothDeviceFound。

    2023-08-01 15:09

  • 1***@qq.com

    谢谢,加了allowDuplicatesKey: true有用

    2024-07-08 11:42

1***@qq.com

1***@qq.com

加allowDuplicatesKey: true

要回复问题请先登录注册