2017-02-13 15 views
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 

プロパティに関するもう一つの問題は、nRFConnectreadwritenotifyを示しなぜBluetooth SIG

enter image description here

によります。しかし、それは実際に特性の正しい価値を得ています。

enter image description here

+2

読み取り要求を発行し、CBPeripheralDelegateメソッド「didUpdateValue」へのコールバックを取得するまで、値はnilになります。 – Paulw11

+0

あなたがそれを発見したときに 'func readValue(特性:CBCharacteristic)'を呼び出します。または、setNotify(charに使用可能な場合)。 – Larme

+0

それは動作します。どのようにプロパティについては? – WeiJay

答えて

0

特性の値を読み取ります。 swift 4

関連する問題