美文网首页
IOS 蓝牙

IOS 蓝牙

作者: 小暖风 | 来源:发表于2017-12-12 16:44 被阅读8次

1,几个主要的类

CBCentralManager,该类的对象用于管理发现的或者连接的外围设备。;

CBCentral,代表中心设备;

CBPeripheral,代表外围设备,每个外围设备通过 UUID 来标识。外围设备可以包含一个或者多个服务、或者提供关于连接的信号强度的信息;

CBPeripheralManager,外设管理器。

2.流程

如果是作为中心设备,首先要创建CBCentralManager对象。

self.centralManager= [[CBCentralManageralloc]initWithDelegate:selfqueue:dispatch_get_main_queue()];

创建后,会回调代理方法

- (void)centralManagerDidUpdateState:(CBCentralManager*)central。

然后根据central的state参数判断蓝牙是否可用。

扫描周围蓝牙设备是

[central scanForPeripheralsWithServices:nil options:nil];

central就是CBCentralManager的对象。如果Services传nil则是扫描周边所有蓝牙外设,如果传CBUUID对象的数组,则是扫描特定的外设。

相关文章

网友评论

      本文标题:IOS 蓝牙

      本文链接:https://www.haomeiwen.com/subject/fohnixtx.html