如何从CBC特征中获得确切的价值?

问题描述:

<CBCharacteristic: 0x156d48cf0, UUID = BLevel, properties = 0x18, value = <32353732 380d0a>, notifying = YES> 

我想提取价值领域里有什么。如何从CBC特征中获得确切的价值?

NSData *data = c.value; // c is of type CBCharacteristic 

但我不知道它是哪种价值?

+0

你需要知道什么意思了'NSData'。可能是一个字符串,结构,uint32等请参阅:http://*.com/questions/38718841/ios-core-bluetooth-get-all-features-description-from-device/38719661#38719661是'BLevel '关于电池电量?你需要做反向engeenering或阅读文档(BLE文档,如果它是“已知的”或设备文档) – Larme

+0

@Larme,是的,它是“电池电量”。你是那种类型的? – Hemang

+0

据商务部:https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.battery_level.xml如果它的UUID 0x2A19,但似乎长了INT8。 – Larme

您可以转换NSDataNSString使用

NSString *str = [[NSString alloc] initWithData:c.value encoding:NSUTF8StringEncoding];