1,避免蓝牙搜索设备有缓存
蓝牙搜索成功后关闭蓝牙设备也还是能搜索得到,需要加上allowDuplicatesKey: false
wx.startBluetoothDevicesDiscovery({
allowDuplicatesKey: false,
success: function(res) {
console.log(res);
},
});
2、安卓机打印一次后无法连接蓝牙打印机并再次打印的问题
需要把wx.writeBLECharacteristicValue方法添加延时
setTimeout(() => {
wx.writeBLECharacteristicValue({
deviceId: this.BLEInformation.deviceId,
serviceId: this.BLEInformation.writeServiceId,
characteristicId: this.BLEInformation.writeCharaterId,
value: buf,
success: function(res) {
}
})
},50)
3、wx.getConnectedBluetoothDevices方法获取不到servers
改成uni.getConnectedBluetoothDevices方法
4、使用低功耗蓝牙原生写法
// 使用低功耗蓝牙原生写法
console.log(this.BLEInformation);
// var value = new ArrayBuffer(8);
// var iv = new Int32Array(value);
// (iv[0] = 120), (iv[2] = 100);
// console.log(value);
// plus.bluetooth.writeBLECharacteristicValue({
// deviceId: this.BLEInformation.deviceId,
// serviceId: this.BLEInformation.writeServiceId,
// characteristicId: this.BLEInformation.writeCharaterId,
// value: value,
// success: function (e) {
// console.log("write characteristics success: " + JSON.stringify(e));
// },
// fail: function (e) {
// console.log("write characteristics failed: " + JSON.stringify(e));
// },
// });
5、getBLEDeviceServices方法如果获取到的servers为空数组,需要在方法外加延迟
setTimeout(() => {},5000)