我正在开发iOS核心蓝牙应用程序,我可以使用iPad3连接BLE设备。我能够到达didDiscoverServices
区块,但无法从此处继续。
我的问题是;
帮助我或提供任何建议。
感谢Wilhelmsen的回复。
我从上面提到的块中得到了以下内容:
[0] - Service : <CBConcreteService: 0x1769a0> UUID: Generic Attribute Profile
[1] - Service : <CBConcreteService: 0x174470> UUID: Generic Access Profile
[2] - Service : <CBConcreteService: 0x1744e0> UUID: Unknown (<00005301 00000041 4c505749 53450000>)
Characteristic
[0] - Characteristic : <CBConcreteCharacteristic: 0x15d410> UUID: Service Changed
[0] - Characteristic : <CBConcreteCharacteristic: 0x1805b0> UUID: Device Name
[1] - Characteristic : <CBConcreteCharacteristic: 0x1806a0> UUID: Appearence
[0] - Characteristic : <CBConcreteCharacteristic: 0x183810> UUID: Unknown (<00004301 00000041 4c505749 53450000>)
[1] - Characteristic : <CBConcreteCharacteristic: 0x1838a0> UUID: Unknown (<00004302 00000041 4c505749 53450000>)
现在如何在didUpdateValueForCharacteristic块中获取此特征的确切值?
答案 0 :(得分:12)
通过框架好好阅读。如果你到目前为止,你应该没有任何问题找到'discoverCharacteristics'和外围代表回调'didDiscoverCharacteristic'。您需要知道要发现的服务和特征的UUID,并将其应用于这些方法。
然后你可以阅读'readValueForCharacteristic'和委托回调'didUpdateValueForCharacteristic'。
这是从我的手机发送的,所以当我上电脑时我可能会编辑一下。希望它有所帮助
新问题:
[connectedPeripheral readValueForCharacteristic:wantedCharacteristic]
和外围代表
- (void) peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error{
NSLog(@"Characteristic value : %@ with ID %@", characteristic.value, characteristic.UUID);
[delegate characteristicValueRead:characteristic.value];
}
适合我
答案 1 :(得分:2)
您可以获得特征的价值
NSString *value = [[NSString alloc] initWithData:characteristic.value encoding:NSUTF8StringEncoding];
NSLog(@"Value %@",value);
答案 2 :(得分:0)
只需使用 https://github.com/LGBluetooth/LGBluetooth
[LGUtils readDataFromCharactUUID:@"f045"
seriveUUID:@"5ec0"
peripheral:peripheral
completion:^(NSData *data, NSError *error) {
NSLog(@"Data : %s Error : %@", (char *)[data bytes], error);
}];