BHBluetooth 0.1.7

BHBluetooth 0.1.7

Maintained by XB-Paul.



  • By
  • 学宝

蓝牙管理器-iOS

CI Status Version License Platform

简介

  1. 蓝牙中心设备检索外围蓝牙设备
  2. 连接外围设备

特点

  1. 检索到的外围设备列表,支持过滤外围蓝牙名称为空的设备
  2. 支持连接不同类型的外围蓝牙设备
  3. 通过自定义的类型标签,获取已连接的外围设备
  4. 支持Delegate和Notification

使用

pod 'BHBluetooth'
设置监听
[BHCentralManager shareInstance].delegate = self; //设置回调
//[BHCentralManager shareInstance].ignorePeripheralIfUnnamed = YES; //配置是否忽略外围设备名称为空的设备
发现外围设备(蓝牙已打开)
- (void)centralManager:(BHCentralManager *)centralManager didUpdateState:(BHCentralManagerState)state {
    if (state == BHCentralManagerStatePoweredOn) {
        [[BHCentralManager shareInstance] startScan];//开始扫描
    }
}
连接
- (void)centralManager:(BHCentralManager *)centralManager didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary<NSString *,id> *)advertisementData RSSI:(NSNumber *)RSSI {
    if (你确定外围设备keyboardtype的逻辑) {
    [[BHCentralManager shareInstance] connectPeripheral:peripheral options:nil typeIdentifier:@"keyboardtype"];
    }
}

注:连接逻辑根据自己的业务定。

作者

学宝 [email protected]

写出你能看懂的代码,而不只是机器能读懂的代码。