微信版本号 :8.0及以上
手机链接上蓝牙设备后1-5秒内会触发onBLEConnectionStateChange函数 返回false 蓝牙链接被断开 提示 The connection has timed out unexpectedly
wx.onBLEConnectionStateChange(function(res) {
console.log(res.deviceId + "连接状态:" + res.connected)
if(res.connected == false){
console.log(res.deviceId + "连接状态connectedconnected:" + res.connected)
uni.onBluetoothAdapterStateChange(res=>{
//监听蓝牙适配器是否打开,若打开则自动搜索蓝牙设备(onBluetoothAdapterStateChange)
if (res.available) {
store.commit('isblueTooth',true)
that.startBluetoothDevicesDiscovery();
}
});
// that.openBluetoothAdapter()
// store.state.connected
store.commit("connected",false);
store.commit("isblueTooth",false);
}
})
请具体描述问题出现的流程,并提供能复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。
wx.createBLEConnection
wx.getBLEDeviceCharacteristics
监听连接变化的代码
wx.onBLEConnectionStateChange(function (res) {
wx.showModal({
title: '提示',
showCancel: false,
content: '连接意外断开:' + 'device state has changed:' + res.deviceId + '|' + 'connected:' + res.connected,
success: function (res) {
if (res.confirm) {
return;
}
}
})
})
其中 res.connected返回false,整合流程就是这样
楼主你好,请问这个问题你后来解决了嘛,可以分享一下解决思路么。谢谢你