我正在尝试使用CoreBluetooth框架获取IOS8及以上版本中所有附近蓝牙设备和任何类型蓝牙设备的配对设备的列表。我使用下面的方法来获取所有附近可用的蓝牙设备的列表,但该方法没有被调用。
- (void)viewDidLoad
{
[super viewDidLoad];
// Start up the CBCentralManager
_centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
// And somewhere to store the incoming data
_data = [[NSMutableData alloc] init];
}
- (void)centralManagerDidUpdateState:(CBCentralManager *)central
{
if (central.state != CBCentralManagerStatePoweredOn) {
// In a real app, you'd deal with all the states correctly
return;
}
// The state must be CBCentralManagerStatePoweredOn...
// ... so start scanning
[self scan];
}
- (void)scan
{
[self.centralManager scanForPeripheralsWithServices:nil
options:nil];
NSLog(@"Scanning started");
}
- (void)centralManager:(CBCentralManager *)central
didDiscoverPeripheral:(CBPeripheral *)peripheral
advertisementData:(NSDictionary *)advertisementData
RSSI:(NSNumber *)RSSI
{
NSString *thePeripheralName = peripheral.name;
}
我可以使用BluetoothManager Framework执行这两项任务,但这是Apple的私有框架,Apple Itunes不会批准我的应用程序进行实时发布。