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

已更新code未更新文档内容

  • 一些方法细节修改,增加代码的兼容性和健壮性

  • 添加一个新的方法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();

考虑或计划更新的功能

====================== 修改filterblock的参数,把外设添加进去 ====================== 添加一个尝试重连设备的委托,对设备重连功能进行进一步的扩展。 ======================= 修改链式方法为command模式 ====================== 支持swift,Android,js,react-native

搁浅的更新

====================== 添加一个尝试重连设备的委托,对设备重连功能进行进一步的扩展。 =======================增加一个和检验工具方法http://www.jianshu.com/p/a5e25206df39 =======================优化app demo,从工程中分离出去 ,添加ui,点击进入教程,github蓝牙库 =======================用断言优化babybluetooth链式方法调用顺序的检查 =======================初始化CBCentralManager指定queue方法,注意是否可以再次初始化重新制定运行线程。 =======================添加定时阅读rssi的方法 =======================增加对复杂操作的支持 =======================对象改名方案 Babyblahblahblah

当一系列操作后执行的方法

//方法声明
-(void)until:(void (^)())step
       then:(void(^)(CBCentralManager *manager,CBPeripheral *peripheral))then;
-(void)until:(void (^)())step
        step:(void (^)())step;
//方法调用

 [baby 
     until:^() {
        //获取characteristic
        fetchC(characteristicc1,"ff01");
        //characteristic write操作
        writeC(characteristicc1,"ff01");
        writeC(characteristicc2,characteristicc1);
        //检查是否写成功,默认write就会检查是否写成功
        ckeckValueEqual(characteristicc1,characteristicc2);
        //check Block检查

        
     }
     then:^(CBCentralManager *manager,CBPeripheral *peripheral) {
        //do when step done
        notity(c3,c4,onBlock());
     }
 ];

 [baby until:^{
        //
    } step:^{
        //
    } then:^(CBCentralManager *manager, CBPeripheral *peripheral) {
        
  }];

//#warning 测试数据 ////个性化,读取设备养护数据 //-(void)readPlantAssistantData{ // //写入当前系统时间 //
// CBCharacteristic *currentTime = [BabyToy findCharacteristicFormServices:self.services UUIDString:@"FFA8"]; //
// if (currentTime) { // NSMutableData *data = [NSMutableData data]; // NSDateFormatter *df = [[NSDateFormatter alloc]init]; // [df setDateFormat:@"yyyy/MM/dd/hh/mm"]; // NSArray *dateArray = df stringFromDate:[NSDate date componentsSeparatedByString:@"/"]; // for (NSString *item in dateArray) { // int intItem = [item intValue]; // if (intItem > 1000) { // int hPart = intItem/100; // int lPart = intItem%2000; // [data appendData:[NSData dataWithBytes:&hPart length:1]]; // [data appendData:[NSData dataWithBytes:&lPart length:1]]; // } // else{ // [data appendData:[NSData dataWithBytes:&intItem length:1]]; // } //
// } // // [self.currPeripheral writeValue:data forCharacteristic:currentTime type:CBCharacteristicWriteWithResponse]; // } // // //读取当前RecordStartTime(FFA2)RecordPeriod(FFAB) CurrentTime(FFA8),ReadID(FFA4),ReadOT(FFA5) //
// //设置ReadID,ReadOT //
// //TransferStatus(FFA9) 写1 // CBCharacteristic *transferStatus = [BabyToy findCharacteristicFormServices:self.services UUIDString:@"FFA9"]; // // if (transferStatus) { // int i = 1; // NSData *value = [NSData dataWithBytes:&i length:sizeof(i)]; // [self.currPeripheral writeValue:value forCharacteristic:transferStatus type:CBCharacteristicWriteWithResponse]; // } // //订阅RecordBuf(FFA1)数据 // CBCharacteristic *recordBuf = [BabyToy findCharacteristicFormServices:self.services UUIDString:@"FFA1"]; // // if (recordBuf) { // [self.currPeripheral setNotifyValue:YES forCharacteristic:recordBuf]; // } //
//}