安卓手机蓝牙连接一直失败,设置了五分钟的超时时间还是不行,监听蓝牙状态改变的回调
wx.onBLEConnectionStateChange,蓝牙的状态有时是连接有时是未连接,
wx.createBLEConnection这个方法的success一直不走,走fail的方法,错误信息是10006/10012;iOS测试没有问题;求教
连接代码如下:
//连接蓝牙 – 暴露给外界
function connectBluetoothDevices(device, isFunction) {
connectCallBack = isFunction;
stopBluetoothDevicesDiscovery();
currentDevice = deviceInfo;
deviceId = device[‘devices’][0][‘deviceId’];
console.log(‘要去连接蓝牙啦!’);
wx.createBLEConnection({
deviceId: deviceId,
timeout:300000,
success: function (res) {
console.log(‘连接成功’);
getBluetoothDeviceServices(device)
},
fail: function (error) {
console.log(error);
console.log(‘连接失败’);
closeBluetoothConnect();
connectBluetoothDevices(device, isFunction);
}
})
}