ZHBLE 使用 Block 回调方法,旨在简化系统 CoreBluetooth 库的函数调用。
使用简单便捷的蓝牙。
类名 | 函数和用法 |
---|---|
ZHBLECentral | 作为中心端的设备和相关操作,例如:初始化中心、扫描、连接、获取设备。 |
ZHBLEPeripheral | 周边操作,如:发现服务和特征、监听、读写等。 |
ZHBLEPeripheralManager | 作为周边设备操作,例如初始化 CBPeripheralManager、广播、添加服务和发送数据。 |
ZHBLEStoredPeripherals | 设备本地缓存操作 |
ZHBLEManager | 快速访问最近连接的设备 |
ZHBLEBlocks | 所有 Block 定义 |
#import "ZHBLE.h"
self.central = [ZHBLECentral sharedZHBLECentral];
//Scan
[self.central scanPeripheralWithServices:uuids options:@{CBCentralManagerScanOptionAllowDuplicatesKey: @(YES)} onUpdated:^(ZHBLEPeripheral *peripheral,NSDictionary *data){
if (peripheral) {
//Do Something
}}];
//Connection
[self.central connectPeripheral:peripheral options:nil onFinished:^(ZHBLEPeripheral *peripheral, NSError *error){
}];
#import "ZHBLE.h"
self.peripheralManager = [ZHBLEPeripheralManager sharedZHBLEPeripheralManager];
//Advertise
CBUUID *temUUID = [CBUUID UUIDWithString:@"902DD287-69BE-4ADD-AACF-AA3C24D83B66"];
NSArray *temUUIDArray = [NSArray arrayWithObjects:temUUID, nil];
NSDictionary *temServiceDic = @{CBAdvertisementDataServiceUUIDsKey:temUUIDArray};
[self.peripheralManager startAdvertising:temServiceDic onStarted:^(NSError *error){
}];
//Add Service
[self.peripheralManager addService:_transferService onFinish:^(CBService *service,NSError *error){
}];
代码在 MIT 许可证 的条款和条件下分发。