我正在寻找一种仅连接到基于 RSSI的最近外围设备的方法。我的目标是列出其他外围设备,但只有最近的外围设备连接。
由于 RSSI 仅在设备连接时可用,等到所有设备都连接然后根据 RSSI 确定最近的外围设备然后断开其余设备是否有意义?
连接
- (void) connectToPeripheral:(CBPeripheral *)peripheral
{
NSDictionary * options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:FALSE],CBConnectPeripheralOptionNotifyOnDisconnectionKey,nil];
[myCBCentralManager connectPeripheral:peripheral options:options];
}
使用的代表
- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI
- (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error;
- (void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral;
CBP外设
/*!
* @property RSSI
*
* @discussion While connected, the RSSI of the link in decibels.
*/
@property(retain, readonly) NSNumber *RSSI;