https://github.com/coolnameismy/BabyBluetooth github上的一个ios 蓝牙4.0的库并带文档和教程

时间:2015-11-23 13:23:33   收藏:0   阅读:1700

 

技术分享

The easiest way to use Bluetooth (BLE )in ios,even bady can use. 简单易用的蓝牙库,基于CoreBluetooth的封装,并兼容ios和mac osx.

为什么使用它?

当前版本 v0.4.0

详细文档请参考wiki The full documentation of the project is available on its wiki.

english readme link,please click it!

Table Of Contents

QuickExample

//导入.h文件和系统蓝牙库的头文件
#import "BabyBluetooth.h"
//定义变量
BabyBluetooth *baby;

-(void)viewDidLoad {
    [super viewDidLoad];

    //初始化BabyBluetooth 蓝牙库
    baby = [BabyBluetooth shareBabyBluetooth];
    //设置蓝牙委托
    [self babyDelegate];
    //设置委托后直接可以使用,无需等待CBCentralManagerStatePoweredOn状态
    baby.scanForPeripherals().begin();
}

//设置蓝牙委托
-(void)babyDelegate{

    //设置扫描到设备的委托
    [baby setBlockOnDiscoverToPeripherals:^(CBCentralManager *central, CBPeripheral *peripheral, NSDictionary *advertisementData, NSNumber *RSSI) {
        NSLog(@"搜索到了设备:%@",peripheral.name);
    }];

    //过滤器
    //设置查找设备的过滤器
    [baby setFilterOnDiscoverPeripherals:^BOOL(NSString *peripheralName) {
        //设置查找规则是名称大于1 , the search rule is peripheral.name length > 1
        if (peripheralName.length >1) {
            return YES;
        }
        return NO;
    }];
}

如何安装

1 手动安装

step1:将项目Classes/objc 文件夹中的文件直接拖入你的项目中即可

step2:导入.h文件

#import "BabyBluetooth.h"

2 cocoapods

step1:add the following line to your Podfile:

pod ‘BabyBluetooth‘,‘~> 0.4.0‘

step2:导入.h文件

#import "BabyBluetooth.h"

如何使用

用法请见wiki

示例程序说明

BabyBluetoothExamples/BabyBluetoothAppDemo :一个类似lightblue的程序,蓝牙操作全部使用BabyBluetooch完成。 功能:

BabyBluetoothExamples/BabyBluetoothOSDemo :一个mac os程序,因为os和ios的蓝牙底层方法都一样,所以BabyBluetooth可以ios/os通用。但是os程序有个好处就是直接可以在mac上跑蓝牙设备,不像ios,必须要真机才能跑蓝牙设备。所以不能真机调试时可以使用os尝试蓝牙库的使用。

功能:

BabyBluetoothExamples/BluetoothStubOnOSX :一个mac os程序,该程序可以作为蓝牙外设使用,解决学习蓝牙时没有外设可用的囧境,并且可以作为peripheral model模式的学习示例。改程序用swift编码。

功能:

兼容性

后期更新

已经更新的版本说明,请在wiki中查看

蓝牙学习资源

qq交流群:426603940

期待

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!