蓝牙api allowDuplicatesKey参数设置
wx.startBluetoothDevicesDiscovery(OBJECT)
根据文档所述我调用该api时将allowDuplicatesKey设为了false,在
wx.onBluetoothDeviceFound(CALLBACK)这个回调内依然检测出deviceId和name相同的设备
剔除业务逻辑后的代码如下:
wx.openBluetoothAdapter({ // 初始化蓝牙适配器 success: function (res) { wx.startBluetoothDevicesDiscovery({ // 开始搜寻附近的蓝牙外围设备 allowDuplicatesKey: false, success: function (res) { wx.getBluetoothDevices({ // 获取所有已发现的蓝牙设备,包括已经和本机处于连接状态的设备 success: function (res) { wx.hideLoading(); }, fail: function (res) { wx.hideLoading(); } }) wx.onBluetoothDeviceFound(function (devices) { console.log(devices.devices[0]); }) }, fail: function (res) { wx.hideLoading(); } }) }, fail: function (res) { wx.hideLoading(); } }) |
调试结果:
可以看到console出来的设备有很多是重复的这里仅列举了一个,不知道是使用的姿势不对吗?调试用的真机是iOS10.3.2,微信版本是6.5.9
