【发布时间】:2014-12-31 15:29:49
【问题描述】:
当电池状态发生变化时,我连接了多个 BLE 设备,每个“通知”。
在收到状态更改通知后,如何识别读取数据时通知的是哪个 BLE?
// Instance method to get the battery state
- (void) getBattery:(CBCharacteristic *)characteristic
{
//----------------
NSLog(@"getBattery");
//----------------
{
// Get the Battery Data
NSLog(@"Battery Level is : %@ (HEX)" , characteristic.value);
}
}
这是收到通知时读取数据的代码...
感谢您的回答,但我似乎只接收来自上次服务设置的数据以进行通知。这是Notify的调用代码...
嗨,太好了。当数据发生变化时,我可以识别通知设备。
但是,我的代码似乎只是从最后识别的特征中通知和收集数据。
这里是调用代码:
- (void)peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error
{
// Retrieve the characteristic value for battery
if ([characteristic.UUID isEqual:[CBUUID UUIDWithString:SR1_DEVICE_BATTERY_LEVEL_SERVICE_UUID]]) {
[self getBattery:characteristic];
}
}
【问题讨论】:
标签: objective-c cocoa bluetooth-lowenergy