在ios设备下,调用wx.createBLEPeripheralServer,没有任何反应,三个回调都不执行,但相同小程序android可以使用。ios设备为iphone8,代码如下
wx.openBluetoothAdapter({
success: (res) => {
console.log('open adpater')
wx.createBLEPeripheralServer({
success: (result) => {
console.log('create success')
let server = result.server
let name = 'xxxxxx'
server.startAdvertising({
advertiseRequest: {
connected : true,
deviceName : name,
}
}).then(
(res) => {
console.log('advertising',res)
},
(res) => {
console.warn('ad fail',res)
}
)
},
fail: (res) => {
console.log('creat fail')
},
complete: (res) => {
console.log('complete')
}
})
},
fail: (res) => {
console.log('open failed')
console.warn(res)
},
complete: (res) => {
console.log('open complete')
}
})
wx.openBluetoothAdapter需要加上mode:'peripheral'参数
加上mode:'peripheral' OK了
server.addService({
service: {
uuid: uuid1,
characteristics: [{
uuid: '0000xxxx-0000-0000-0000-00xxxxxx',
value: 'Hello',
permissions: {
read: true,
write: true,
writeWithoutResponse: true
},
descriptors: [{
uuid: '0000xxxx-0000-0000-0000-00xxxxxx',
value: 'Hello Descriptor'
}]
}]
},
success: function (res) {
console.log('添加服务成功')
},
fail: function (res) {
console.error('添加服务失败', res)
}
})
请问下可以这样加服务特征吗?