Wil*_*jay 5 ios core-bluetooth bluetooth-lowenergy swift
我目前正在使用 CoreBluetooth 开发 BLE 设备。我可以通过找到我的设备CBCentralManagerDelegate并连接到我的设备。
当我想发现一个服务的特性时,我可以得到正确的uuid,但是特性的值是nil。有任何想法吗?
func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?) {
if error != nil {
print("ERROR DISCOVERING CHARACTERISTICS: \(error?.localizedDescription)")
return
}
if let characteristics = service.characteristics {
for characteristic in characteristics {
print("--------------------------------------------")
print("Characteristic UUID: \(characteristic.uuid)")
print("Characteristic isNotifying: \(characteristic.isNotifying)")
print("Characteristic properties: \(characteristic.properties)")
print("Characteristic descriptors: \(characteristic.descriptors)")
print("Characteristic value: \(characteristic.value)")
}
}
}
-------------------------------------------------------------------
Characteristic UUID: FA01
Characteristic isNotifying: false
Characteristic properties: CBCharacteristicProperties(rawValue: 26)
Characteristic descriptors: nil
Characteristic value: nil
Run Code Online (Sandbox Code Playgroud)
根据蓝牙 SIG 的说法,关于属性的另一个问题
为什么nRFConnect出现read, write, notify. 但它确实得到了特征的正确值。
读取特征值。迅捷4
func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?) {
for newChar: CBCharacteristic in service.characteristics!{
peripheral.readValue(for: newChar)
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6347 次 |
| 最近记录: |