openBluetooth: function () {
const that = this;
wx.openBluetoothAdapter({
success(res) {
console.log("打开蓝牙成功", res);
},
fail(res) {
console.log("打开蓝牙失败", res)
if (res.errCode = "10001") {
wx.showModal({
title: '提示',
content: '检查蓝牙是否开启',
})
}
}
})
wx.getBluetoothAdapterState({
success: function (res) {
console.log("获取蓝牙初始化状态", res)
that.searchNearBluetooth();
},
fail: function (res) {
console.log("获取蓝牙初始化状态失败", res)
}
})
},
searchNearBluetooth: function () {
const that = this;
// 搜索附近蓝牙设备
wx.startBluetoothDevicesDiscovery({
success: function (res) {
console.log("搜索蓝牙设备", res)
wx.showToast({
title: '',
icon: 'loading',
duration: 3000
})
that.foundBluetooth();
},
fail: function (res) {
console.log("搜索失败时", res)
}
})
},
小米9,MIUI11.05,微信版本7.0.10