自定义UUID在IOS示例中对BLE的意义是什么?

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.应用程序可以选择一个centralPeripheral,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"蓝牙开发门户中找不到这个.是通过建立uuidgenterminal

The second Question:

如果我是Central,并且我characteristic通过使用setNotifyValue:YES像上面的代码订阅了.

BLE会告诉以下代码Central发送新数据Peripheral,概念是否正确?

- (void)peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error

我是IOS开发和BLE的新手.

提前致谢.

Eta*_*tan 7

第一个问题:

  • 是的,Apple甚至建议uuidgen在各种WWDC视频中使用这些UUID .蓝牙SIG未对128位UUID进行标准化,您可以使用这些UUID运行自己的配置文件.

第二个问题:

  • 是的,那么你首先发现服务,然后是特征setNotifyValue:YES.从现在开始,您将收到来自外围设备的通知[-CBPeripheralDelegate didUpdateValueForCharacteristic:error:].当您手动读取特征时,将调用相同的回调(无法区分读取响应与核心蓝牙中的通知).