Ios 在具有相同服务和特征的多个设备中建立蓝牙设备连接?
我有多个BLE设备,它们具有相同的服务和特性。我可以扫描和连接多个设备。连接后,尝试通过发送命令来区分每个连接,但不起作用。它与单个设备完美配合。是不是有点像插座连接?就像服务器产生子线程一样,每个客户端都可以通过线程维护连接。请提供有关如何识别每个设备的一些提示 我创建的CBCentralManager实例是singletonIos 在具有相同服务和特征的多个设备中建立蓝牙设备连接?,ios,core-bluetooth,Ios,Core Bluetooth,我有多个BLE设备,它们具有相同的服务和特性。我可以扫描和连接多个设备。连接后,尝试通过发送命令来区分每个连接,但不起作用。它与单个设备完美配合。是不是有点像插座连接?就像服务器产生子线程一样,每个客户端都可以通过线程维护连接。请提供有关如何识别每个设备的一些提示 我创建的CBCentralManager实例是singleton + (id) sharedInstance { static BLEConnectionManager *this = nil; if (!thi
+ (id) sharedInstance
{
static BLEConnectionManager *this = nil;
if (!this) {
this = [[BLEConnectionManager alloc] init];
}
else {
[this scanDevice];
}
return this;
}
-(void) scanDevice {
[centralManager scanForPeripheralsWithServices:nil options:0];
}
- (id) init
{
centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
peripherals = [[NSMutableArray alloc] init];
[centralManager scanForPeripheralsWithServices:nil options:0];
return self;
}
===
编辑
这样行吗?在为每个设备建立连接之后,我将在didConnectPeripheral委派方法中创建一个实例处理服务和特性,如Apple提供的temperatureSensor示例。因此,每个设备分别维护一个连接
- (void) centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral
{
service = [[[LeTemperatureAlarmService alloc] initWithPeripheral:peripheral controller:peripheralDelegate] autorelease];
[service start];
}