小程序 iOS系统 BLEPeripheralServer.addService 返回 {errno: 1509000, errMsg: "addBLEPeripheralService:ok"};
安卓系统返回 {errno: 0,errCode: 0, errMsg: "addBLEPeripheralService:ok"}
导致无法连接BLE蓝牙设备
iOS版本:15.4.1
型号:iPhone 6s Plus
示例代码:
const baseServiceId = '07CEDB7C-0A62-A8D6-57E2-C9BB0E4EB60B'
const baseCharacteristicId = '07CEDB7C-0A62-A8D6-57E2-C9BB0E4EB60C'
openBluetoothAdapter() {
wx.openBluetoothAdapter({
mode: 'peripheral',
success: (res) => {
console.log("openBluetoothAdapter(peripheral for iOS):", res);
this.createBLEPeripheralServer();
},
fail: (res) => {
console.error("openBluetoothAdapter (peripheral for iOS) error:", res)
}
})
},
createBLEPeripheralServer() {
wx.createBLEPeripheralServer({
success: (result) => {
console.log('外围Server创建成功', result);
if (result.server) {
this.addBLEPeripheralServices(result.server)
}
},
fail: (err) => {
console.log('外围Server创建失败', err);
}
})
},
addBLEPeripheralServices(server) {
server.addService({
service: {
uuid: baseServiceId,
characteristics: [{
uuid: baseCharacteristicId,
properties: {
writeNoResponse: true,
read: true
},
permission: {
writeable: true,
readable: true
}
}]
},
success: (res) => {
console.log('添加Service结果', res);
if (res.errno == 0) {
console.log('添加Service成功');
}
else if (res.errno == 1509000) {
wx.showToast({
title: "蓝牙设备未知错误",
icon: "error"
})
}
},
fail: (err) => {
console.log('添加Service失败', err);
}
})
},
iOS端创建Service时报1509000错误
大佬 addService什么意思,和createBLEPeripheralServer有什么区别?
该问题提交几天了,都没有任何回复???
const charaBuffer = new ArrayBuffer(1)
const dataView = new DataView(charaBuffer)
dataView.setUint8(0, 0)
this.blePeripheralServer.addService({
service: {
uuid: baseServiceId,
characteristics: [{
uuid: baseCharacteristicId,
properties: {
writeNoResponse: true,
read: true,
},
permission: {
writeable: true,
readable: true
},
value: charaBuffer
}],
},
....
})