ZHBLE using Block callback methods, aimed at making the system CoreBluetooth library function is called simple.
- Based on the original CoreBluetooth, the callback function all packaged into Block mode, calls the associated function simplicity.。
- Central and Peripheral side has packages。
- Using the factory pattern and Block integration makes it easier for initialization and function calls.
simple and convenient to use Bluetooth。
- iOS 7.0+
- ARC
- CoreBluetooth.framework
Class name | Function and usage |
---|---|
ZHBLECentral | Equipment as the relevant attributes and operations on the Central side, for example: initialize Central, scanned, connect, retrieve equipment. |
ZHBLEPeripheral | Peripheral-side operations such as: discovery service and features, listening, reading and writing, and so on. |
ZHBLEPeripheralManager | Device as a Peripheral-side operations such as initialization of CBPeripheralManager, radio, adding services and send data. |
ZHBLEStoredPeripherals | Equipment local cache operations |
ZHBLEManager | Fast access to recently connected devices |
ZHBLEBlocks | All Block definitio |
CocoaPods (recommended)
pod '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){
}];
This code is distributed under the terms and conditions of the MIT license.