一、开始搜索周围蓝牙设备
wxml方面:
bindtap绑定一个事件startBluetoothDevicesDiscovery
<button bindtap="startBluetoothDevicesDiscovery">2.开始搜索周围蓝牙设备</button>
JS方面:
该事件(startBluetoothDevicesDiscovery)在JS中表示如下,参考微信官方文档openBluetoothAdapter
//②开始搜索周围蓝牙设备
startBluetoothDevicesDiscovery(){
var that=this
// 以微信硬件平台的蓝牙智能灯为例,主服务的 UUID 是 FEE7。传入这个参数,只搜索主服务 UUID 为 FEE7 的设备,services: ['FEE7']
wx.startBluetoothDevicesDiscovery({
services: [],//此处变成搜索周围所有设备
success (res) {
console.log(res)
that.setData({
discoverFlag:res.isDiscovering//定义一个标志,方便后面用
})
}
})
},
data定义discoverFlag