-(void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI
{
if (![discoverPeripherals containsObject:peripheral])
{
[discoverPeripherals addObject:peripheral];
NSLog(@"rssi: %@", RSSI);
[rssiArray addObject:RSSI];
peripheral.delegate =self;
NSNumber *max=[rssiArray valueForKeyPath:@"@max.intValue"];
NSLog(@"max.intValue: %@", max);
int rssi=abs([[rssiArray valueForKeyPath:@"@max.intValue"] intValue]);
if (rssi<=40)
{
self.discoverPeripherals=peripheral;
[CBManager connectPeripheral:self.currentPeripheral options:Nil];
}
}
else
{
for (int i=0; i<discoverPeripherals.count ; i++)
{
CBPeripheral *thisPeripheral =[discoverPeripherals objectAtIndex:i];
if (thisPeripheral == peripheral)
{
[rssiArray replaceObjectAtIndex:i withObject:RSSI];
NSLog(@"rssi: %@", RSSI);
}
}
请帮助您连接最近的BLE设备。我能够获取rssi值但不能连接它们。谢谢