不明白为什么无法获取到手机的蓝牙地址
/*开启蓝牙设备*/
openBluetoothAdapter: function () {
var that = this;
wx.openBluetoothAdapter({
success: function (res) {
console.log(res)
wx.onBluetoothAdapterStateChange(function (res) {
console.log("蓝牙适配器状态变化", res)
that.setData({
isbluetoothready: res.available,
searchingstatus: res.discovering
})
})
that.startBluetoothDevicesDiscovery()
}
})
},
/*获取本机蓝牙适配器状态*/
getBluetoothAdapterState: function () {
var that = this;
wx.getBluetoothAdapterState({
success: function (res) {
console.log(res)
if (!res.discovering) {
that.startBluetoothDevicesDiscovery()
}
}
})
},
startBluetoothDevicesDiscovery: function () {
var that = this;
wx.startBluetoothDevicesDiscovery({
allowDuplicatesKey: true,
success: function (res) {
console.log(res)
},
fail: function (res) {
console.log(res)
},
})
that.onBluetoothDeviceFound();
},
/**获取在微信小程序蓝牙模块生效期间所有已发现的蓝牙设备,微信小程序已发布,安卓手机无法被搜索,苹果手机部分搜不到,急急急!!#微信小程序开发教程 ...。包括已经和本机处于连接状态的设备。*/
getBluetoothDevices: function () {
var that = this;
wx.getBluetoothDevices({
success: function (res) {
console.log(res)
}
})
},
/**监听寻找到新设备的事件*/
onBluetoothDeviceFound: function () {
var that = this;
that.getConnectedBluetoothDevices()
console.log("search............")
wx.onBluetoothDeviceFound(function (devices) {
console.log('new device list has founded')
console.dir(devices)
that.getBluetoothDevices()
})
},
/**根据 uuid 获取处于已连接状态的设备*/
getConnectedBluetoothDevices: function () {
var that = this;
that.createBLEConnection()
wx.getConnectedBluetoothDevices({
success: function (res) {
console.log(res)
//
}
})
},