华为P50 -鸿蒙4.2.0系统,微信是最新版本,初始化蓝牙适配器,创建服务成功,发广播成功,多次连接断开后,调用BLEPeripheralServer.addService进入err报错,如图所示:
代码如下:
let characteristics = [
{
properties: {
read: true,
write: true,
notify: true,
},
permission: {
readable: true,
writeable: true
},,
uuid: CHARACTERISTIC_UUID,
},
];
characteristics.forEach((characteristic) => {
if (that.data.phone === 'ios') {
characteristic.value = new Uint8Array([0x00, 0x00]).buffer;
} else if (that.data.phone === 'android') {
characteristic.descriptors = [{
uuid: DESCRIPTORS_UUID,
permission: {
read: true,
write: true
},
}];
}
});
// 添加服务
that.data.server?.addService({
service: {
uuid: SERVICEID,
characteristics: characteristics,
},
success: () => {
console.log('服务特征值创建成功');
//发送广播
that.data.server?.startAdvertising({
advertiseRequest: {
deviceName:"test",
serviceUuids: [SERVICEID]
},
powerLevel: 'high',
success: (res) => { console.log('开始广播啦!!!')},
fail: (err) => {console.error('广播失败啦', err)}
})
},
fail: (err) => { console.log('服务特征值创建失败');}
});
你好,麻烦在手机微信那里上传下日志: 我->设置->帮助与反馈右上角有个上报日志的入口,麻烦提供一下微信号,时间点