问题遇到的现象和发生背景
如何解决uniapp蓝牙接口uni.writeBLECharacteristicValue写入成功,安卓端
不返回回调数据,ios端正常。
问题相关代码,请勿粘贴截图
//开启监听
notify() {
uni.notifyBLECharacteristicValueChange({
state: true,
type: 'notification',
deviceId: this.deviceId,
serviceId: this.serviceId,
characteristicId: this.characteristicId,
success: (res) => {
console.log('开启消息监听成功', res),
setTimeout(() => {
this.listen()
}, 300),
setTimeout(() => {
this.write()
}, 300)
},
fail: (err) => {
console.log('开启消息监听失败', err)
}
})
},
write() {
//写入读取全部数据
let msg = '4E 57 00 13 00 00 00 00 06 03 00 00 00 00 00 00 68 00 00 01 29'
let typedArray = new Uint8Array(msg.match(/[\da-f]{2}/gi).map(function(h) {
return parseInt(h, 16)
}))
let buffer1 = typedArray.buffer
uni.writeBLECharacteristicValue({
deviceId: this.deviceId,
serviceId: this.serviceId,
characteristicId: this.characteristicId,
value: buffer1,
writeType: 'write',
success: res => {
console.log(res)
},
fail: err => {
console.log(err)
},
complete: com => {
console.log(com)
}
})
},
运行结果及报错内容
12:13:35.982 [Object] {"errMsg":"writeBLECharacteristicValue:ok"} at pages/index/index.vue:631
12:13:36.015 [Object] {"errMsg":"writeBLECharacteristicValue:ok"} at pages/index/index.vue:637