进入小程序,先提示用户打开蓝牙,之后再进行下一步操作
Page({
onLoad: function (options) {
this.startBlue();
},
startBlue: function () {
var _this = this;
wx.openBluetoothAdapter({//初始化蓝牙模块
success: function (res) {
console.log("蓝牙可用,可进入下一步")
},
fail() {
_this.showTip();
wx.onBluetoothAdapterStateChange(function (res) {//监听蓝牙打开关闭
if (res.available) {
console.log("蓝牙可用,可进入下一步")
}
})
}
})
},
showTip: function () {
wx.showToast({
title: '请打开蓝牙',
duration: 2500
})
}
})