Wun*_*Wun 5 bluetooth objective-c ios core-bluetooth bluetooth-lowenergy
我是iOS开发的新手,并且正在研究Bluetooth Low Energy (BLE, Bluetooth 4.0)
IOS.
我研究了这个链接BTLE Central Peripheral Transfer的示例代码.
此链接iOS 7 SDK中还有另一个类似的示例:Core Bluetooth - Practical Lesson
以上两个链接上的应用程序在send and receive the text data
两个IOS设备之间进行了讨论BLE
.应用程序可以选择一个central
或Peripheral
,central
并将收到从中发送的文本数据Peripheral
.
它定义了UUID
类似下面的代码header file
.
#define TRANSFER_CHARACTERISTIC_UUID @"08590F7E-DB05-467E-8757-72F6FAEB13D4"
Run Code Online (Sandbox Code Playgroud)
并且在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.
}
Run Code Online (Sandbox Code Playgroud)
The question is like the following:
First Question:
我UUID:@"08590F7E-DB05-467E-8757-72F6FAEB13D4"
在蓝牙开发门户中找不到这个.是通过建立uuidgen
在terminal
?
The second Question:
如果我是Central
,并且我characteristic
通过使用setNotifyValue:YES
像上面的代码订阅了.
BLE会告诉以下代码Central
发送新数据Peripheral
,概念是否正确?
- (void)peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error
我是IOS开发和BLE的新手.
提前致谢.
第一个问题:
uuidgen
在各种WWDC视频中使用这些UUID .蓝牙SIG未对128位UUID进行标准化,您可以使用这些UUID运行自己的配置文件.第二个问题:
setNotifyValue:YES
.从现在开始,您将收到来自外围设备的通知[-CBPeripheralDelegate didUpdateValueForCharacteristic:error:]
.当您手动读取特征时,将调用相同的回调(无法区分读取响应与核心蓝牙中的通知). 归档时间: |
|
查看次数: |
3506 次 |
最近记录: |