Skip to content
coolnameismy edited this page May 5, 2016 · 23 revisions

大家要是有什么想要的功能可以提出,如果我觉得适合我会在后续版本更新。可以issue或者email联系我。

当前

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

  • 添加了一个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;

v0.3

  • 添加了一个babyRhythm辅助类,用户帮助用户监控蓝牙的操作情况
  • 添加了10个新的委托block
    
    //连接Peripherals失败的委托
    -(void)setBlockOnFailToConnect:(void (^)(CBCentralManager *central,CBPeripheral *peripheral,NSError *error))block;
     //断开Peripherals的连接
    -(void)setBlockOnDisconnect:(void (^)(CBCentralManager *central,CBPeripheral *peripheral,NSError *error))block;
    
    //连接Peripherals失败的委托
    -(void)setBlockOnFailToConnectAtChannel:(NSString *)channel
                                      block:(void (^)(CBCentralManager *central,CBPeripheral *peripheral,NSError *error))block;
    //断开Peripherals的连接
    -(void)setBlockOnDisconnectAtChannel:(NSString *)channel
                                   block:(void (^)(CBCentralManager *central,CBPeripheral *peripheral,NSError *error))block; 
   
    /#pragma mark -babybluetooth Special

    //babyBluettooth cancelScan方法调用后的回调
    -(void)setBlockOnCancelScanBlock:(void(^)(CBCentralManager *centralManager))block;
   
    //babyBluettooth cancelAllPeripheralsConnectionBlock 方法调用后的回调
    -(void)setBlockOnCancelAllPeripheralsConnectionBlock:(void(^)(CBCentralManager *centralManager))block;
   
    //babyBluettooth cancelPeripheralConnection 方法调用后的回调
    -(void)setBlockOnCancelPeripheralConnectionBlock:(void(^)(CBCentralManager *centralManager,CBPeripheral *peripheral))block;
    
    //babyBluettooth cancelScan方法调用后的回调
    -(void)setBlockOnCancelScanBlockAtChannel:(NSString *)channel
                                             block:(void(^)(CBCentralManager *centralManager))block;
    //babyBluettooth cancelAllPeripheralsConnectionBlock 方法调用后的回调
    -(void)setBlockOnCancelAllPeripheralsConnectionBlockAtChannel:(NSString *)channel
                                                                 block:(void(^)(CBCentralManager *centralManager))block;
    //babyBluettooth cancelPeripheralConnection 方法调用后的回调
    -(void)setBlockOnCancelPeripheralConnectionBlockAtChannel:(NSString *)channel
                                                             block:(void(^)(CBCentralManager *centralManager,CBPeripheral *peripheral))block;
  • 去除xcode7 产生的警告
  • 精简了readme,将相关内容移至wiki
  • 增加了后台模式的支持和说明
  • 增加了baby运行时(如扫描,连接,发现服务和字节的参数设置)
//设置蓝牙运行时的参数
-(void)setBabyOptionsWithScanForPeripheralsWithOptions:(NSDictionary *) scanForPeripheralsWithOptions
                          connectPeripheralWithOptions:(NSDictionary *) connectPeripheralWithOptions
                        scanForPeripheralsWithServices:(NSArray *)scanForPeripheralsWithServices
                                  discoverWithServices:(NSArray *)discoverWithServices
                           discoverWithCharacteristics:(NSArray *)discoverWithCharacteristics;

//设置蓝牙运行时的参数 channel版
-(void)setBabyOptionsAtChannel:(NSString *)channel
 scanForPeripheralsWithOptions:(NSDictionary *) scanForPeripheralsWithOptions
  connectPeripheralWithOptions:(NSDictionary *) connectPeripheralWithOptions
scanForPeripheralsWithServices:(NSArray *)scanForPeripheralsWithServices
          discoverWithServices:(NSArray *)discoverWithServices
   discoverWithCharacteristics:(NSArray *)discoverWithCharacteristics;

使用示例:

    /*设置babyOptions
        参数分别使用在下面这几个地方,若不使用参数则传nil
        - [centralManager scanForPeripheralsWithServices:scanForPeripheralsWithServices options:scanForPeripheralsWithOptions];
        - [centralManager connectPeripheral:peripheral options:connectPeripheralWithOptions];
        - [peripheral discoverServices:discoverWithServices];
        - [peripheral discoverCharacteristics:discoverWithCharacteristics forService:service];
        该方法支持channel版本:
            [baby setBabyOptionsAtChannel:<#(NSString *)#> scanForPeripheralsWithOptions:<#(NSDictionary *)#> connectPeripheralWithOptions:<#(NSDictionary *)#> scanForPeripheralsWithServices:<#(NSArray *)#> discoverWithServices:<#(NSArray *)#> discoverWithCharacteristics:<#(NSArray *)#>]
     */
    
    //扫描选项->CBCentralManagerScanOptionAllowDuplicatesKey:忽略同一个Peripheral端的多个发现事件被聚合成一个发现事件
    NSDictionary *scanForPeripheralsWithOptions = @{CBCentralManagerScanOptionAllowDuplicatesKey:@YES};
    /*连接选项-> 只在非后台模式下才起作用
     CBConnectPeripheralOptionNotifyOnConnectionKey :当应用挂起时,如果有一个连接成功时,如果我们想要系统为指定的peripheral显示一个提示时,就使用这个key值。
     CBConnectPeripheralOptionNotifyOnDisconnectionKey :当应用挂起时,如果连接断开时,如果我们想要系统为指定的peripheral显示一个断开连接的提示时,就使用这个key值。
     CBConnectPeripheralOptionNotifyOnNotificationKey:
     当应用挂起时,使用该key值表示只要接收到给定peripheral端的通知就显示一个提
    */
     NSDictionary *connectOptions = @{CBConnectPeripheralOptionNotifyOnConnectionKey:@YES,
     CBConnectPeripheralOptionNotifyOnDisconnectionKey:@YES,
     CBConnectPeripheralOptionNotifyOnNotificationKey:@YES};
    
    [baby setBabyOptionsAtChannel:channelOnPeropheralView scanForPeripheralsWithOptions:scanForPeripheralsWithOptions connectPeripheralWithOptions:connectOptions scanForPeripheralsWithServices:nil discoverWithServices:nil discoverWithCharacteristics:nil];
    

v0.2

  • 1:添加peripheral连接失败和连接断开连接的委托
  • 2:现在begin()链式方法可以初始化后直接执行,不必等待PoweredOn状态。
  • 3:修改channel委托方法又xxxOnChannel改为AtChannel
	//之前
    baby = [BabyBluetooth shareBabyBluetooth];
    //...设置委托
    //因为蓝牙设备打开需要时间,所以只有监听到蓝牙设备状态打开后才能安全的使用蓝牙
    [baby setBlockOnCentralManagerDidUpdateState:^(CBCentralManager *central) {
        if (central.state == CBCentralManagerStatePoweredOn) {
            //扫描设备 
            baby.scanForPeripherals().begin();
        }
    }];

	//现在
	baby = [BabyBluetooth shareBabyBluetooth];
	//...设置委托
	//设置委托后直接可以使用,无需等待CBCentralManagerStatePoweredOn状态。
	baby.scanForPeripherals().begin();

更新日期:2015/09/12

##v0.1 1:完成BlayBluetooch蓝牙基本操作功能 2:链式蓝牙操作方法 3:channel切换委托回叫

更新日期:2015/09/06

Clone this wiki locally