【发布时间】:2014-06-01 07:59:23
【问题描述】:
我是 iOS 开发的新手,正在研究 iOS 的 Bluetooth Low Energy (BLE, Bluetooth 4.0)。
我研究了这个链接BTLE Central Peripheral Transfer的示例代码。
这个链接里还有另一个类似的例子iOS 7 SDK: Core Bluetooth - Practical Lesson
以上两个链接上的应用程序在BLE 的基础上讨论了两个IOS 设备之间的send and receive the text data。
App可以选择central或者Peripheral,central会接收Peripheral发送的文本数据。
它定义了UUID,就像header file中的以下代码一样。
#define TRANSFER_CHARACTERISTIC_UUID @"08590F7E-DB05-467E-8757-72F6FAEB13D4"
Central连接到Peripheral后,发现Peripheral的特征。
如果 UUID 等于 TRANSFER_CHARACTERISTIC_UUID ,则使用 setNotifyValue:YES 订阅它,如下代码所示。
- (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error
{
// Again, we loop through the array, just in case.
for (CBCharacteristic *characteristic in service.characteristics) {
// And check if it's the right one
if ([characteristic.UUID isEqual:[CBUUID UUIDWithString:TRANSFER_CHARACTERISTIC_UUID]]) {
// If it is, subscribe to it
[peripheral setNotifyValue:YES forCharacteristic:characteristic];
}
}
// Once this is complete, we just need to wait for the data to come in.
}
The question is like the following:
First Question:
我在Bluetooth Development Portal 中找不到这个UUID:@"08590F7E-DB05-467E-8757-72F6FAEB13D4"。
这是 uuidgen 在 terminal 中创建的吗?
The second Question:
如果我是 Central ,并且我已经像上面的代码一样使用 setNotifyValue:YES 订阅了 characteristic。
BLE 会通过以下代码告诉 Central 有来自 Peripheral 的新数据发送,这个概念是否正确?
- (void)peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error
我是IOS开发和BLE的新手。
提前致谢。
【问题讨论】:
-
对于第一个问题:长 UUID 是自定义 UUID(而标准 UUID 使用 4hex)。这意味着它们不尊重任何标准,因为它们还不存在或者因为它们是特定的/专有的。
标签: ios objective-c bluetooth bluetooth-lowenergy core-bluetooth