收藏
回答

wx.readBLECharacteristicValue在ios手机上出现10004?

为什么在安卓手机中直接调用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)
      }
    })
  },
回答关注问题邀请回答
收藏

1 个回答

  • Demons
    Demons
    2022-07-06

    请具体描述问题出现的流程,并提供能复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。

    2022-07-06
    有用
    回复 2
    • 瘦到八十斤的梦想
      瘦到八十斤的梦想
      2022-07-06
      这个是必现问题啊  你们按照流程调用一下api就能出现这个问题的  我所有的代码就在上面贴着
      2022-07-06
      回复
    • 李
      2023-01-04回复瘦到八十斤的梦想
      这帮人工资太好拿了 每次都是这句话 就没下文了
      2023-01-04
      回复
登录 后发表内容