2
私は現在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
プロパティに関するもう一つの問題は、nRFConnectはread
、write
、notify
を示しなぜBluetooth SIG
によります。しかし、それは実際に特性の正しい価値を得ています。
読み取り要求を発行し、CBPeripheralDelegateメソッド「didUpdateValue」へのコールバックを取得するまで、値はnilになります。 – Paulw11
あなたがそれを発見したときに 'func readValue(特性:CBCharacteristic)'を呼び出します。または、setNotify(charに使用可能な場合)。 – Larme
それは動作します。どのようにプロパティについては? – WeiJay