为什么在安卓手机中直接调用wx.readBLECharacteristicValue可以正常从wx.onBLECharacteristicValue拿到数据?在ios手机上必须保证获取服务-->获取特特征值---->读特征值---->订阅特征值这个步骤,直接从读特征值会出现10004错误或者直接获取特征值也会出现10004错误?
async onLoad() {
this.setData({
curDeviceId: wx.getStorageSync('curDeviceId') ? wx.getStorageSync('curDeviceId') : ''
})
wx.onBLECharacteristicValueChange(res => {
console.log(`${LOG_PREFIX} on BLECharacteristicValueChange res:`, res, config.getMiiteeIdcharacteristicId)
if (res.characteristicId == config.getMiiteeIdcharacteristicId) {
const miiteeId: string = ab2str(res.value)
this.setData({
miiteeId: miiteeId
})
console.log(`${LOG_PREFIX} get miiteeId:`, miiteeId)
this.getDeviceName(miiteeId)
}
})
await this.handleGetServices()
},
async handleGetServices() {
console.log("CONNECTION Page handleGetServices", this.data.curDeviceId)
return new Promise((resolve, reject) => {
wx.getBLEDeviceServices({
deviceId: this.data.curDeviceId,
success: (res) => {
console.log(`CONNECTION Page getBLEDeviceServices res:`, res)
this.handleGetCharacteristics()
resolve(0)
},
fail: (error) => {
console.error(`CONNECTION Page getBLEDeviceServices error:`, error)
reject(1)
}
})
})
},
async handleGetCharacteristics() {
console.log(`${LOG_PREFIX} handleGetCharacteristics`, this.data.curDeviceId)
return new Promise((resolve, reject) => {
wx.getBLEDeviceCharacteristics({
deviceId: this.data.curDeviceId,
serviceId: config.serviceId,
success: async (res) => {
console.log(`${LOG_PREFIX} getBLEDeviceCharacteristics success res:`, res)
await this.handleReadCharacteristics()
resolve(0)
},
fail: (error) => {
console.error(`${LOG_PREFIX} getBLEDeviceCharacteristics error:`, error)
reject(1)
}
})
})
},
handleReadCharacteristics() {
return new Promise((resolve, reject) => {
console.log(`CONNECTION Page handleReadCharacteristics`, config.getMiiteeIdcharacteristicId)
wx.readBLECharacteristicValue({
deviceId: wx.getStorageSync('curDeviceId'),
serviceId: config.serviceId,
characteristicId: config.getMiiteeIdcharacteristicId,
success: (res) => {
console.log(`CONNECTION Page readBLECharacteristicValue res:`, res)
resolve(0)
this.handleNotifyCharacteristics()
},
fail: (error) => {
reject(1)
console.error(`CONNECTION Page readBLECharacteristicValue error:`, error)
}
})
})
},
handleNotifyCharacteristics() {
wx.notifyBLECharacteristicValueChange({
deviceId: wx.getStorageSync('curDeviceId'),
serviceId: config.serviceId,
characteristicId: this.data.characteristicId,
state: true,
success: (res) => {
console.log(`${LOG_PREFIX} notifyBLECharacteristicValueChange success:`, res)
},
fail: (error) => {
console.error(`${LOG_PREFIX} notifyBLECharacteristicValueChange fail:`, error)
}
})
},
请具体描述问题出现的流程,并提供能复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。