使用CoreBluetooth对接欧姆龙Evolv血压计2A35特征值为空问题咨询
核心遗漏环节与解决方法
1. 未确认Indicate订阅的实际结果
你当前日志显示2A35的notifying = NO,说明你调用的setNotifyValue(true, for: char)请求根本没有执行成功。你需要先实现CBPeripheralDelegate的peripheral(_:didUpdateNotificationStateFor:error:)代理方法,查看订阅失败的具体原因:
- 欧姆龙血压计的Indicate特征需要加密链路才能订阅,若未完成设备配对(绑定),系统会直接拒绝订阅请求。如果订阅报错提示权限不足,可以先主动读取2A49特征触发系统的配对弹窗,输入设备配对码(通常为0000/1234,部分型号会在设备屏幕显示)完成配对后再重新订阅。
2. 未实现Indicate数据接收的代理方法
2A35特征仅支持Indicate属性,不支持Read操作,你调用readValue无法获取数值,Indicate推送的数据会通过peripheral(_:didUpdateValueFor:error:)代理方法返回,你未实现该方法自然无法拿到测量值。
3. 缺少RACP特征的交互步骤
欧姆龙带存储功能的血压计不会在订阅2A35后主动推送历史数据,你需要额外调用血压服务(UUID 1810)下的记录访问控制点特征(RACP,UUID 2A52),发送获取历史记录的指令,设备才会将存储的测量值通过2A35的Indicate推送给你。
补充代码示例
// 订阅状态变更回调 func peripheral(_ peripheral: CBPeripheral, didUpdateNotificationStateFor characteristic: CBCharacteristic, error: Error?) { if let error = error { print("特征\(characteristic.uuid)订阅失败: \(error)") // 权限不足时触发配对 peripheral.readValue(for: characteristic) return } // 2A35订阅成功后发送RACP指令拉取数据 if characteristic.uuid == CBUUID(string: "2A35"), characteristic.isNotifying { guard let racpChar = peripheral.services?.first(where: { $0.uuid == CBUUID(string: "1810") })? .characteristics?.first(where: { $0.uuid == CBUUID(string: "2A52") }) else { return } // 拉取所有历史测量记录的RACP指令 let fetchAllCmd = Data([0x01, 0x01]) peripheral.writeValue(fetchAllCmd, for: racpChar, type: .withResponse) } } // 特征值更新回调,Indicate数据会走这个方法 func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?) { guard let data = characteristic.value, error == nil else { return } if characteristic.uuid == CBUUID(string: "2A35") { // 按照BLS规范解析2A35的血压数据即可 print("收到血压测量数据: \(data)") } }
内容的提问来源于stack exchange,提问作者Dennissimeau
相关产品推荐
相关产品推荐

