通过NFC拉起小程序,自动根据提前存入到NFC标签mac地址去匹配附近蓝牙设备进行连接,安卓端经常会出现 wx.startBluetoothDevicesDiscovery 不执行?导致搜索不到附近设备进行连接!(安卓端有问题,ios无问题)
代码片段
// NFC进入连接方法
HomeNFCConnect (NFCmac) {
wx.openBluetoothAdapter({
success: async (res) => {
logger.info('HomeNFCConnect NFCmac: ', NFCmac)
// 以下方法 有时执行,有时不执行
wx.startBluetoothDevicesDiscovery({
allowDuplicatesKey: wx.getStorageSync('platform') == 'ios' ? false : true,
interval: 0,
powerLevel: 'high',
success: async (res) => {
logger.info('HomeNFCConnect startBluetoothDevicesDiscovery NFCmac: ', NFCmac)
await wx.onBluetoothDeviceFound(async ({ devices }) => {
const { localName, name, advertisData, connectable, deviceId } = devices[0]
})
},
fail: async (error) => {
logger.info('HomeNFCConnect startBluetoothDevicesDiscovery error: ', error)
this.initBlue()
if (error.errno == 1509008) { // 需要开启位置才能搜索蓝牙
wx.showToast({
title: '请前往手机应用微信设置中开启位置权限',
icon: 'error',
duration: 1500
})
}
}
})
},
fail: (error) => {
wx.showToast({
title: 'openBluetoothAdapter error ' + error,
icon: 'error',
duration: 3000
})
}
})
},
线上日志如下:
有无大佬遇到过