//获取应用实例
const app = getApp()
Page({
data: {
},
onLoad: function () {
wx.openBluetoothAdapter({
success: function (res) {
console.info(res);
},
fail: function (res) {
console.info(res);
wx.showModal({
title: ‘提示’,
content: ‘监测到系统未开启蓝牙,请前往设置开启蓝牙模块!’,
})
}
})
wx.onBluetoothAdapterStateChange(function (res) {
console.log(`adapterState changed, now is`, res)
if (res.available) {
wx.showToast({
title: ‘蓝牙已开启’
});
} else {
wx.showToast({
title: ‘蓝牙已关闭’
});
}
})
wx.startBluetoothDevicesDiscovery({
success: function (res) {
console.log(res)
}
})
setTimeout(function (res) {
wx.getBluetoothDevices({
success: function (res) {
console.log(res)
}
})
}, 10000);
wx.onBluetoothDeviceFound(function (devices) {
console.log(‘new device list has founded’)
console.dir(devices);
wx.getBluetoothDevices({
success: function (res) {
console.log(res)
}
})
})
},
getBluetoothDevices: function () {
let that = this;
wx.getBluetoothDevices({
success: function (res4) {
console.log(res4);
for (let item of res4.devices) {
console.log(item.name.trim())
console.log(item.name.trim().length)
}
}
})
},
startsearch:function(){
wx.startBluetoothDevicesDiscovery({
success: function (res) {
console.log(res)
}
})
},
})
我这样写得到的array永远为0,用了多个真机调试都没用,是不是蓝牙模块有问题?