在IOS中检测IOS7中启用蓝牙的iPhone设备

我在我的应用程序中使用核心蓝牙框架。

我知道如何扫描外围设备并从中获取数据(如心率监视器)

但我想要的是检索周围的iPhone设备列表,支持BLE 4.0和蓝牙启用的。

我提到下面的链接..

使用IOBluetooth Framework

使用CoreBluetooth获取外设而不是设备列表

- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI { // I'm not sure how to make this work NSLog (@"Discovered peripheral: %@", [peripheral name]); [self.list addObject:peripheral.name]; // add peripheral name to foundarray NSLog (@"UUID peripheral: %@", [peripheral UUID]); NSLog (@"peripheral services before connected: %@", [peripheral services]); NSLog(@"adversting data %@",[NSString stringWithFormat:@"%@",[advertisementData description]]); NSLog(@"foundArray is %@", self.list); } - (void)centralManagerDidUpdateState:(CBCentralManager *)central { NSLog(@"Central manager's state is updated to: %@", central); if(central.state == CBCentralManagerStatePoweredOn) { //okay your good to go and can now scan } else { //Unable to use CentralManager methods so print out the central.state and find out why } } 

我不知道苹果是否提供这个或不。

任何build议或意见将不胜感激..

预先感谢..

尝试下面的代码checkBluetoothAccessrequestBluetoothAccess方法

  - (void)checkBluetoothAccess { if(!self.cbManager) { self.cbManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil]; } /* We can ask the bluetooth manager ahead of time what the authorization status is for our bundle and take the appropriate action. */ CBCentralManagerState state = [self.cbManager state]; if(state == CBCentralManagerStateUnknown) { [self alertViewWithDataClass:Bluetooth status:NSLocalizedString(@"UNKNOWN", @"")]; } else if(state == CBCentralManagerStateUnauthorized) { [self alertViewWithDataClass:Bluetooth status:NSLocalizedString(@"DENIED", @"")]; } else { [self alertViewWithDataClass:Bluetooth status:NSLocalizedString(@"GRANTED", @"")]; } } 

 - (void)requestBluetoothAccess { if(!self.cbManager) { self.cbManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil]; } /* When the application requests to start scanning for bluetooth devices that is when the user is presented with a consent dialog. */ [self.cbManager scanForPeripheralsWithServices:nil options:nil]; } 

您只能检索支持蓝牙4.0的周边iOS设备,如果他们也在广告特定的服务以识别它们。 你不能只看到所有的电源和附近的iOS设备。 如果他们是广告,你可以扫描零,这将返回正在看到的广告数据包。

注意:如果您关心的是检索当前从其他应用程序连接的BLE设备,则可以使用retrieveConnectedPeripheralsWithServices:方法。