执行常见的Periphral角色任务
peripheralManagerDidUpdateState:是peripheral manager 的代理对象的方法。
那么使用这个UUID建立一个CBUUID对象,如下:
建立services 和 characteristic的树
第一步,建立一个Peripheral Manager,进行分配和初初始化,通过CBPeriphralManager类方法initWithDelegate:queue:options
myPeripheralManager = |
[[CBPeripheralManager alloc] initWithDelegate:self queue:nil options:nil]; |
第二步,建立services和Characteristics
通过UUIDS来识别services和Characteristics,128bit的蓝牙特定UUIDS,由Core Bluetooth框架的CBUUID对象表示。
Bluetooth SIG为了方便使用提供了16-bit的UUID,可以通过使用UUIDWithString方法来简化为service预定义的16-bit UUID
例如:
CBUUID *heartRateServiceUUID = [CBUUID UUIDWithString: @"180D"];
当你建立了一个预定义16-bitUUID的CBUUID对象时,Core Bluetooth会基于Bluetooth 基础 UUID 来预先填充上128-bitUUID剩余的部分。
如果services 和 characteristics 没有预定义的Bluetooth 16-bit UUIDs,则需要产生一个128-bit UUIDs来识别它们。
在Terminal窗口里,利用命令uuidgen来产生128-bit的UUIDs,如下:
$ uuidgen |
71DA3FD1-7E10-41C1-B16F-4430B506CDE7 |
CBUUID *myCustomServiceUUID = |
[CBUUID UUIDWithString:@"71DA3FD1-7E10-41C1-B16F-4430B506CDE7"]; |