姚浩然 2022-08-27 15:30
浏览 138
已结题

如何解决uniapp蓝牙接口uni.writeBLECharacteristicValue写入成功,安卓端不返回回调数据?ios端回调正常。

问题遇到的现象和发生背景

如何解决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

  • 写回答

0条回答 默认 最新

    报告相同问题?

    问题事件

    • 系统已结题 9月4日
    • 创建了问题 8月27日

    悬赏问题

    • ¥15 节日彩灯电路设计电路图
    • ¥15 esp32cam串口图传
    • ¥15 C# 用partial定义部分类无法快速预览代码
    • ¥15 fastreport 代码无法设置最后一页横线不显示
    • ¥15 stm32u535芯片usb hid custom类接收数据有问题
    • ¥15 ue5.3 pico打包失败 求帮助
    • ¥15 请教,这是用chatgpt写的CAD LISPD脚本,需求是画一个由双直线组成的矩形
    • ¥50 微信小程序 成功包奶茶啊
    • ¥15 计算机博弈的六子棋代码
    • ¥15 在Fetch API中传送的参数为何不起作用?