ZHBLE 0.2.1

ZHBLE 0.2.1

TestsTested
LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release Sep 2017

Maintained by zhuozhuo.




ZHBLE 0.2.1

  • By
  • Mr.jiang

ZHBLE using Block callback methods, aimed at making the system CoreBluetooth library function is called simple.

Screenshot0    Screenshot1   

Chinese README LINK

Features

  • 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.

Design Goals

simple and convenient to use Bluetooth。

Requirements

  • iOS 7.0+
  • ARC
  • CoreBluetooth.framework

Introduce

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

Usage

Copy the folder ZHBLE to your project

Central

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

Peripheral

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

License

This code is distributed under the terms and conditions of the MIT license.