Releases: coolnameismy/BabyBluetooth
Releases · coolnameismy/BabyBluetooth
0.7.0
setBlockOnReadValueForDescriptors
委托中的一个参数命名错误,把参数名CBDescriptor *descriptorNSError
改为CBDescriptor *descriptor
- 一些方法细节修改,增加代码的兼容性和健壮性
- 添加一个新的方法enjoy() ,相当于链式方法中的
connectToPeripherals().discoverServices().discoverCharacteristics().readValueForCharacteristic().discoverDescriptorsForCharacteristic().readValueForDescriptors().begin();
简写,这个方法是一个语法糖,可以减少代码量。 - 完善测试用例
- 提取Babybluetooth中一些默认行为的常量,统一放在BabyDefine.h文件中
- 修复findConnectPeripheral中的一个bug fixed #35
- 添加一个开关,控制Babybluetooth中打印的日志是否开启 ,使用方式可以通过修改源码
BabyDefine.h #define BABY_IS_SHOW_LOG 1
0为不打印,1为打印日志 - 修复一个当discoveryPeripheral block未设置时会导致discoveryPeripheralFilter不起作用的bug"
- 添加蓝牙中心模式各种事件的委托,使用notification方式做广播,开发者现在不但可以使用block实现委托,也可以使用notification实现各种事件的委托监听,从而得到更为灵活的开发方式,通知类型:
//centralManager status did change notification
#define BabyNotificationAtCentralManagerDidUpdateState @"BabyNotificationAtCentralManagerDidUpdateState"
//did discover peripheral notification
#define BabyNotificationAtDidDiscoverPeripheral @"BabyNotificationAtDidDiscoverPeripheral"
//did connection peripheral notification
#define BabyNotificationAtDidConnectPeripheral @"BabyNotificationAtDidConnectPeripheral"
//did filed connect peripheral notification
#define BabyNotificationAtDidFailToConnectPeripheral @"BabyNotificationAtDidFailToConnectPeripheral"
//did disconnect peripheral notification
#define BabyNotificationAtDidDisconnectPeripheral @"BabyNotificationAtDidDisconnectPeripheral"
//did discover service notification
#define BabyNotificationAtDidDiscoverServices @"BabyNotificationAtDidDiscoverServices"
//did discover characteristics notification
#define BabyNotificationAtDidDiscoverCharacteristicsForService @"BabyNotificationAtDidDiscoverCharacteristicsForService"
//did read or notify characteristic when received value notification
#define BabyNotificationAtDidUpdateValueForCharacteristic @"BabyNotificationAtDidUpdateValueForCharacteristic"
//did write characteristic and response value notification
#define BabyNotificationAtDidWriteValueForCharacteristic @"BabyNotificationAtDidWriteValueForCharacteristic"
//did change characteristis notify status notification
#define BabyNotificationAtDidUpdateNotificationStateForCharacteristic @"BabyNotificationAtDidUpdateNotificationStateForCharacteristic"
//did read rssi and receiced value notification
#define BabyNotificationAtDidReadRSSI @"BabyNotificationAtDidReadRSSI"
//蓝牙扩展通知
// did centralManager enable notification
#define BabyNotificationAtCentralManagerEnable @"BabyNotificationAtCentralManagerEnable"
- 添加了一个方法:根据外设UUID对应的string获取已配对的外设
/**
根据外设UUID对应的string获取已配对的外设
通过方法获取外设后可以直接连接外设,跳过扫描过程
*/
- (CBPeripheral *)retrievePeripheralWithUUIDString:(NSString *)UUIDString;
一个工具方法,用来根据UUIDString获取外设,使用示例:
//快速获取外设
CBPeripheral *p = [baby retrievePeripheralWithUUIDString:@"B19A6ED7-29D5-67EF-0207-6F5AE8BC337B"];
//直接根据外设连接
baby.having(p).connectToPeripherals().begin();
另外,如果不适用最新的api,也可以使用下面的方式达到同样的效果。
NSUUID *uuid = [[NSUUID alloc]initWithUUIDString:@"B19A6ED7-29D5-67EF-0207-6F5AE8BC337B"];
CBPeripheral *p = [self.baby.centralManager retrievePeripheralsWithIdentifiers:@[uuid]][0];
baby.having(p).connectToPeripherals().begin();
0.6.0
- 修改了设置读取到Descriptors方法参数的bug
- 修改了私有变量名 babyBluetooth.m中,私有变量babysiter改名为babyCentralManager
- 根据代码规范优化了代码
- 外设模式中,当未指定外设名称时,增加一个默认名称
- 因为单词拼错导致修改了一个方法名: setFilterOnConnetToPeripherals 改成 setFilterOnConnectToPeripherals
- 在BabyBluetooth.h 文件头几行添加了当前版本号
- 在BabyBluetooth的.h文件中为每个类的一句话的作用描述
- 逐步补充测试用例
- baby添加缓存所有搜索到的外设索引,解决在使用过程中由于未保存peripheral对象可以导致的未知错
- 添加2个方法,用户管理外设的自动重连功能
/**
添加断开自动重连的外设
*/
- (void)AutoReconnect:(CBPeripheral *)peripheral;
/**
删除断开自动重连的外设
*/
- (void)AutoReconnectCancel:(CBPeripheral *)peripheral;
- 搜索和连接的过滤器方法中添加了rssi和advertisementData两个参数
//v0.5.0
/**
设置查找Peripherals的规则
| filter of discover peripherals
*/
- (void)setFilterOnDiscoverPeripherals:(BOOL (^)(NSString *peripheralName))filter;
/**
设置连接Peripherals的规则
| setting filter of connect to peripherals peripherals
*/
- (void)setFilterOnConnectToPeripherals:(BOOL (^)(NSString *peripheralName))filter;
/**
设置查找Peripherals的规则
| filter of discover peripherals
*/
- (void)setFilterOnDiscoverPeripheralsAtChannel:(NSString *)channel
filter:(BOOL (^)(NSString *peripheralName))filter;
/**
设置连接Peripherals的规则
| setting filter of connect to peripherals peripherals
*/
- (void)setFilterOnConnectToPeripheralsAtChannel:(NSString *)channel
filter:(BOOL (^)(NSString *peripheralName))filter;
//0.6.0
/**
设置查找Peripherals的规则
| filter of discover peripherals
*/
- (void)setFilterOnDiscoverPeripherals:(BOOL (^)(NSString *peripheralName, NSDictionary *advertisementData, NSNumber *RSSI))filter;
/**
设置连接Peripherals的规则
| setting filter of connect to peripherals peripherals
*/
- (void)setFilterOnConnectToPeripherals:(BOOL (^)(NSString *peripheralName, NSDictionary *advertisementData, NSNumber *RSSI))filter;
/**
设置查找Peripherals的规则
| filter of discover peripherals
*/
- (void)setFilterOnDiscoverPeripheralsAtChannel:(NSString *)channel
filter:(BOOL (^)(NSString *peripheralName, NSDictionary *advertisementData, NSNumber *RSSI))filter;
/**
设置连接Peripherals的规则
| setting filter of connect to peripherals peripherals
*/
- (void)setFilterOnConnectToPeripheralsAtChannel:(NSString *)channel
filter:(BOOL (^)(NSString *peripheralName, NSDictionary *advertisementData, NSNumber *RSSI))filter;
0.5.0
- 修改了babybluetooth.h 方法的注释
- 添加了babybluetooth对外设模式的支持,现在可以用babybluetooth实现蓝牙设备的模拟
//配置第一个服务s1
CBMutableService *s1 = makeCBService(@"FFF0");
//配置s1的3个characteristic
makeCharacteristicToService(s1, @"FFF1", @"r", @"hello1");//读
makeCharacteristicToService(s1, @"FFF2", @"w", @"hello2");//写
makeCharacteristicToService(s1, genUUID(), @"rw", @"hello3");//读写,自动生成uuid
makeCharacteristicToService(s1, @"FFF4", nil, @"hello4");//默认读写字段
makeCharacteristicToService(s1, @"FFF5", @"n", @"hello5");//notify字段
//配置第一个服务s2
CBMutableService *s2 = makeCBService(@"FFE0");
makeStaticCharacteristicToService(s2, genUUID(), @"hello6", [@"a" dataUsingEncoding:NSUTF8StringEncoding]);//一个含初值的字段,该字段权限只能是只读
//实例化baby
baby = [BabyBluetooth shareBabyBluetooth];
//配置委托
[self babyDelegate];
//添加服务和启动外设
baby.bePeripheral().addServices(@[s1,s2]).startAdvertising();
- 添加block对peripheralManager主要委托的支持
/**
PeripheralManager did update state block
*/
-(void)peripheralModelBlockOnPeripheralManagerDidUpdateState:(void(^)(CBPeripheralManager *peripheral))block;
/**
PeripheralManager did add service block
*/
-(void)peripheralModelBlockOnDidAddService:(void(^)(CBPeripheralManager *peripheral,CBService *service,NSError *error))block;
/**
PeripheralManager did start advertising block
*/
-(void)peripheralModelBlockOnDidStartAdvertising:(void(^)(CBPeripheralManager *peripheral,NSError *error))block;
/**
peripheralManager did receive read request block
*/
-(void)peripheralModelBlockOnDidReceiveReadRequest:(void(^)(CBPeripheralManager *peripheral,CBATTRequest *request))block;
/**
peripheralManager did receive write request block
*/
-(void)peripheralModelBlockOnDidReceiveWriteRequests:(void(^)(CBPeripheralManager *peripheral,NSArray *requests))block;
/**
peripheralManager did subscribe to characteristic block
*/
-(void)peripheralModelBlockOnDidSubscribeToCharacteristic:(void(^)(CBPeripheralManager *peripheral,CBCentral *central,CBCharacteristic *characteristic))block;
/**
peripheralManager did subscribe to characteristic block
*/
-(void)peripheralModelBlockOnDidUnSubscribeToCharacteristic:(void(^)(CBPeripheralManager *peripheral,CBCentral *central,CBCharacteristic *characteristic))block;
- 添加了外设模式的使用示例程序 BabyBluetoothExamples/BluetoothStubOnIOS
- 添加了生成UUID的方法
genUUID()
- 修改了蓝牙中心模式实现类的类名,从babysiter改为babyCentralManager
0.4.0
0.4.0
- 添加了一个demo ,可以作为蓝牙设备被发现、连接、读写、订阅
- 项目支持cocoapods安装,并支持0.3.0 和 0.4.0两个版本
- 增加了对获取RSSI的支持
- 修改了wiki,对使用的每个方法增加了相关委托设置的说明
- 修改了断开链接方法的委托
//方法从 方法调用后的立刻回调 改为-》 方法执行后并且全部设备断开后的回调
-(void)setBlockOnCancelAllPeripheralsConnectionBlock:(void(^)(CBCentralManager *centralManager))block;
//删除了````-(void)cancelPeripheralConnection:(CBPeripheral *)peripheral;````方法调用后的委托
-(void)setBlockOnCancelPeripheralConnectionBlock:(void(^)(CBCentralManager *centralManager,CBPeripheral *peripheral))block;
-(void)setBlockOnCancelPeripheralConnectionBlockAtChannel:(NSString *)channel
block:(void(^)(CBCentralManager *centralManager,CBPeripheral *peripheral))block;
//若想知道设备是否断开可以设置
/*
//断开Peripherals的连接的block
-(void)setBlockOnDisconnect:(void (^)(CBCentralManager *central,CBPeripheral *peripheral,NSError *error))block;
//或
//断开Peripherals的连接的block
-(void)setBlockOnDisconnectAtChannel:(NSString *)channel
block:(void (^)(CBCentralManager *central,CBPeripheral *peripheral,NSError *error))block;
*/
- 添加了获取当前连接的peripheral的方法和获取centralManager的方法
//获取当前连接的peripherals
-(NSArray *)findConnectedPeripherals;
//获取当前连接的peripheral
-(CBPeripheral *)findConnectedPeripheral:(NSString *)peripheralName;
//获取当前corebluetooth的centralManager对象
-(CBCentralManager *)centralManager;
- 增加了14个新的babybluetooth委托
//写Characteristic成功后的block
-(void)setBlockOnDidWriteValueForCharacteristic:(void (^)(CBCharacteristic *characteristic,NSError *error))block;
//写descriptor成功后的block
-(void)setBlockOnDidWriteValueForDescriptor:(void (^)(CBDescriptor *descriptor,NSError *error))block;
//characteristic订阅状态改变的block
-(void)setBlockOnDidUpdateNotificationStateForCharacteristic:(void (^)(CBCharacteristic *characteristic,NSError *error))block;
//读取RSSI的委托
-(void)setBlockOnDidReadRSSI:(void (^)(NSNumber *RSSI,NSError *error))block;
//discoverIncludedServices的回调,暂时在babybluetooth中无作用
-(void)setBlockOnDidDiscoverIncludedServicesForService:(void (^)(CBService *service,NSError *error))block;
//外设更新名字后的block
-(void)setBlockOnDidUpdateName:(void (^)(CBPeripheral *peripheral))block;
//外设更新服务后的block
-(void)setBlockOnDidModifyServices:(void (^)(CBPeripheral *peripheral,NSArray *invalidatedServices))block;
/*channel*/
//写Characteristic成功后的block
-(void)setBlockOnDidWriteValueForCharacteristicAtChannel:(NSString *)channel
block:(void (^)(CBCharacteristic *characteristic,NSError *error))block;
//写descriptor成功后的block
-(void)setBlockOnDidWriteValueForDescriptorAtChannel:(NSString *)channel
block:(void (^)(CBDescriptor *descriptor,NSError *error))block;
//characteristic订阅状态改变的block
-(void)setBlockOnDidUpdateNotificationStateForCharacteristicAtChannel:(NSString *)channel
block:(void (^)(CBCharacteristic *characteristic,NSError *error))block;
//读取RSSI的委托
-(void)setBlockOnDidReadRSSIAtChannel:(NSString *)channel
block:(void (^)(NSNumber *RSSI,NSError *error))block;
//discoverIncludedServices的回调,暂时在babybluetooth中无作用
-(void)setBlockOnDidDiscoverIncludedServicesForServiceAtChannel:(NSString *)channel
block:(void (^)(CBService *service,NSError *error))block;
//外设更新名字后的block
-(void)setBlockOnDidUpdateNameAtChannel:(NSString *)channel
block:(void (^)(CBPeripheral *peripheral))block;
//外设更新服务后的block
-(void)setBlockOnDidModifyServicesAtChannel:(NSString *)channel
block:(void (^)(CBPeripheral *peripheral,NSArray *invalidatedServices))block;
0.3.0
0.3.0
- add a new helper class :babyRhythm which can helper user to monitor Operation
- ten new block about cancel sacn and disconnect peripheral and
//when Peripherals FailToConnect
-(void)setBlockOnFailToConnect:(void (^)(CBCentralManager *central,CBPeripheral *peripheral,NSError *error))block;
//when disconnected Peripherals
-(void)setBlockOnDisconnect:(void (^)(CBCentralManager *central,CBPeripheral *peripheral,NSError *error))block;
//when Peripherals FailToConnect
-(void)setBlockOnFailToConnectAtChannel:(NSString *)channel
block:(void (^)(CBCentralManager *central,CBPeripheral *peripheral,NSError *error))block;
//when disconnected Peripherals
-(void)setBlockOnDisconnectAtChannel:(NSString *)channel
block:(void (^)(CBCentralManager *central,CBPeripheral *peripheral,NSError *error))block;
/#pragma mark -babybluetooth Special
//after babyBluettooth cancelScan
-(void)setBlockOnCancelScanBlock:(void(^)(CBCentralManager *centralManager))block;
//after babyBluettooth cancelAllPeripheralsConnectionBlock
-(void)setBlockOnCancelAllPeripheralsConnectionBlock:(void(^)(CBCentralManager *centralManager))block;
//after babyBluettooth cancelPeripheralConnection
-(void)setBlockOnCancelPeripheralConnectionBlock:(void(^)(CBCentralManager *centralManager,CBPeripheral *peripheral))block;
//after babyBluettooth cancelScan方
-(void)setBlockOnCancelScanBlockAtChannel:(NSString *)channel
block:(void(^)(CBCentralManager *centralManager))block;
//after babyBluettooth cancelAllPeripheralsConnectionBlock
-(void)setBlockOnCancelAllPeripheralsConnectionBlockAtChannel:(NSString *)channel
block:(void(^)(CBCentralManager *centralManager))block;
//after babyBluettooth cancelPeripheralConnection
-(void)setBlockOnCancelPeripheralConnectionBlockAtChannel:(NSString *)channel
block:(void(^)(CBCentralManager *centralManager,CBPeripheral *peripheral))block;
- fix xcode7 waring
- simplify readme,move some content to wiki
- add runtime options for sacn,connect,discover service ...
//set runtime option
-(void)setBabyOptionsWithScanForPeripheralsWithOptions:(NSDictionary *) scanForPeripheralsWithOptions
connectPeripheralWithOptions:(NSDictionary *) connectPeripheralWithOptions
scanForPeripheralsWithServices:(NSArray *)scanForPeripheralsWithServices
discoverWithServices:(NSArray *)discoverWithServices
discoverWithCharacteristics:(NSArray *)discoverWithCharacteristics;
//set runtime option at channel
-(void)setBabyOptionsAtChannel:(NSString *)channel
scanForPeripheralsWithOptions:(NSDictionary *) scanForPeripheralsWithOptions
connectPeripheralWithOptions:(NSDictionary *) connectPeripheralWithOptions
scanForPeripheralsWithServices:(NSArray *)scanForPeripheralsWithServices
discoverWithServices:(NSArray *)discoverWithServices
discoverWithCharacteristics:(NSArray *)discoverWithCharacteristics;
exp:
/*set babyOptions
use in those function,if no option set nil
- [centralManager scanForPeripheralsWithServices:scanForPeripheralsWithServices options:scanForPeripheralsWithOptions];
- [centralManager connectPeripheral:peripheral options:connectPeripheralWithOptions];
- [peripheral discoverServices:discoverWithServices];
- [peripheral discoverCharacteristics:discoverWithCharacteristics forService:service];
at channel function:
[baby setBabyOptionsAtChannel:<#(NSString *)#> scanForPeripheralsWithOptions:<#(NSDictionary *)#> connectPeripheralWithOptions:<#(NSDictionary *)#> scanForPeripheralsWithServices:<#(NSArray *)#> discoverWithServices:<#(NSArray *)#> discoverWithCharacteristics:<#(NSArray *)#>]
*/
//sacnfor options->CBCentralManagerScanOptionAllowDuplicatesKey:忽略同一个Peripheral端的多个发现事件被聚合成一个发现事件
NSDictionary *scanForPeripheralsWithOptions = @{CBCentralManagerScanOptionAllowDuplicatesKey:@YES};
/*connect options-> only works in non-background model
CBConnectPeripheralOptionNotifyOnConnectionKey
CBConnectPeripheralOptionNotifyOnDisconnectionKey
CBConnectPeripheralOptionNotifyOnNotificationKey
*/
NSDictionary *connectOptions = @{CBConnectPeripheralOptionNotifyOnConnectionKey:@YES,
CBConnectPeripheralOptionNotifyOnDisconnectionKey:@YES,
CBConnectPeripheralOptionNotifyOnNotificationKey:@YES};
[baby setBabyOptionsAtChannel:channelOnPeropheralView scanForPeripheralsWithOptions:scanForPeripheralsWithOptions connectPeripheralWithOptions:connectOptions scanForPeripheralsWithServices:nil discoverWithServices:nil discoverWithCharacteristics:nil];