ZHBLE-Bluetooth的封装库

ZHBLE 使用Block回调方式,旨在使调用系统CoreBluetooth库简单明了.

Screenshot0
Screenshot0
Screenshot1
Screenshot1

Screenshot2
Screenshot2
Screenshot3
Screenshot3

Features

  • 基于原生CoreBluetooth,回调函数全部封装成Block方式,使调用相关函数简洁明了。
  • 设备作为Central端和Peripheral端都有封装。
  • 采用工厂模式和Block结合使得初始化和函数调用更容易。

Introduce

类名 作用及用法
ZHBLECentral 设备作为Central端的相关属性和操作例如:初始化Central,扫描,连接,检索设备等。
ZHBLEPeripheral 对Peripheral端的相关操作例如:发现服务和特征,监听,读写等操作。
ZHBLEPeripheralManager 设备作为Peripheral端时的相关操作例如:CBPeripheralManager的初始化,广播,添加服务,发送数据等。
ZHBLEStoredPeripherals 设备本地缓存相关操作
ZHBLEManager 快捷访问最近连接的设备
ZHBLEBlocks 所有Block定义

Usage

CocoaPods (recommended)

pod 'ZHBLE'

Central

#import "ZHBLE.h"

self.central = [ZHBLECentral sharedZHBLECentral];

//扫描

[self.central scanPeripheralWithServices:uuids options:@{CBCentralManagerScanOptionAllowDuplicatesKey: @(YES)} onUpdated:^(ZHBLEPeripheral *peripheral,NSDictionary *data){
        if (peripheral) {
            
            //Do Something
        }
       
    }];

//连接

[self.central connectPeripheral:peripheral options:nil onFinished:^(ZHBLEPeripheral *peripheral, NSError *error){
}onDisconnected:^(ZHBLEPeripheral *peripheral, NSError *error){
                    
        });
    }];

Peripheral

#import "ZHBLE.h"


self.peripheralManager = [ZHBLEPeripheralManager sharedZHBLEPeripheralManager];

//广播

 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){
                       
        }];


//添加服务
[self.peripheralManager addService:_transferService onFinish:^(CBService *service,NSError *error){
        
            }];
            
            

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容