ZHBLE 0.2.1

ZHBLE 0.2.1

测试已测试
语言语言 Obj-CObjective C
许可证 MIT
版本最新版本2017年9月

zhuozhuo 维护。




ZHBLE 0.2.1

  • Mr.jiang

ZHBLE 使用 Block 回调方法,旨在简化系统 CoreBluetooth 库的函数调用。

Screenshot0    Screenshot1   

中文 README 链接

特性

  • 基于原始 CoreBluetooth,所有回调函数都封装成 Block 模式,调用相关函数简化。
  • 中央和周边都有包装。
  • 使用工厂模式和 Block 集成,使初始化和函数调用更容易。

设计目标

使用简单便捷的蓝牙。

要求

  • iOS 7.0+
  • ARC
  • CoreBluetooth.framework

简介

类名 函数和用法
ZHBLECentral 作为中心端的设备和相关操作,例如:初始化中心、扫描、连接、获取设备。
ZHBLEPeripheral 周边操作,如:发现服务和特征、监听、读写等。
ZHBLEPeripheralManager 作为周边设备操作,例如初始化 CBPeripheralManager、广播、添加服务和发送数据。
ZHBLEStoredPeripherals 设备本地缓存操作
ZHBLEManager 快速访问最近连接的设备
ZHBLEBlocks 所有 Block 定义

用法

将 ZHBLE 文件夹复制到您的项目中

中心

#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 许可证 的条款和条件下分发。