清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>
//导入.h文件和系统蓝牙库的头文件 #import <CoreBluetooth/CoreBluetooth.h> #import "BabyBluetooth.h" -(void)viewDidLoad { [super viewDidLoad]; //初始化BabyBluetooth 蓝牙库 baby = [BabyBluetooth shareBabyBluetooth]; //设置蓝牙委托 [self babyDelegate]; __weak typeof(baby) weakBaby = baby; //因为蓝牙设备打开需要时间,所以只有监听到蓝牙设备状态打开后才能安全的使用蓝牙 [baby setBlockOnCentralManagerDidUpdateState:^(CBCentralManager *central) { if (central.state == CBCentralManagerStatePoweredOn) { //开始扫描设备 weakBaby.scanForPeripherals().begin(); } }]; } //蓝牙网关初始化和委托方法设置 -(void)babyDelegate{ //设置扫描到设备的委托 [baby setBlockOnDiscoverToPeripherals:^(CBCentralManager *central, CBPeripheral *peripheral, NSDictionary *advertisementData, NSNumber *RSSI) { NSLog(@"搜索到了设备:%@",peripheral.name); }]; }