Skip to content

StephenCMZ/LSBLEManager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LSBLEManager

一个简易的蓝牙管理器

使用步骤:
  • pod 'LSBLEManager', '~> 1.0.0'
  • 导入LSBluetoothManager.h
  • 设置代理并获取蓝牙管理器
    @interface ConnectDeviceViewController ()<LSBluetoothManagerDelegate>
    LSBluetoothManager *bleManager = [LSBluetoothManager shareBLEManager]; 
    bleManager.delegate = self;
  • 查找蓝牙
	// 查找蓝牙设备
	[bleManager scanDevice];

	// 查找到设备回调
	- (void)updateDevices:(NSArray *)devices{
		// devices 为 CBPeripheral 集合
	} 
  • 连接蓝牙
	//连接蓝牙
	[_bleManager connectDeviceWithCBPeripheral:peripheral
                                andServiceUUID:SERVICEUUID
                   andOutputCharacteristicUUID:OUTPUTUUID
                    andInputCharacteristicUUID:INPUTUUID];

     // 连接状态回调
	- (void)updateStatue:(BLESTATUE)statue{}
  • 收发数据
	//收到数据回调
	- (void)revicedMessage:(NSData *)msg{}
	//发送数据
	NSData data = [NSData dataWithBytes:@"89" length:1];
	[bleManager sendMsg:data];

About

蓝牙管理器

Resources

Stars

Watchers

Forks

Packages

No packages published