我想用CoreBluetooth(如我的應用程序必須符合在App Store)檢查所有當前配對並連接藍牙設備。這不應該需要任何藍牙掃描,對吧?我只想看看系統配對了什麼。如果我不能這樣做,掃描是第二種選擇。(IOS)如何檢查的iPhone的配對的藍牙設備?
我試圖不工作。它表示藍牙未通電並崩潰,但CBCentralManager的狀態爲開啓!任何想法如何解決這個問題,還是我完全偏離軌道?
所有這一切都在視圖控制器現在:
- (void)viewDidLoad{
[super viewDidLoad];
self.centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:dispatch_get_main_queue()];
[self.centralManager retrieveConnectedPeripherals]; //makes the system call didRetrieveConnectedPeripherals
}
- (void)centralManager:(CBCentralManager *)central didRetrieveConnectedPeripherals:(NSArray *)peripherals{
NSLog(@"didRetrieveConnectedPeripherals called");
for (CBPeripheral *a in peripherals){
NSLog(a.name); //just log the name for now to see if it recognized it
} //but it never ends up logging anything, and I have a BT keyboard paired/connected with the iPhone 5
} //and I get an error at some point, <CBConcreteCentralManager: 0x71ab020> is not powered on
- (void)centralManagerDidUpdateState:(CBCentralManager *)manager{
if ([manager state] == CBCentralManagerStatePoweredOff) NSLog(@"CBCentralManagerStatePoweredOff");
if ([manager state] == CBCentralManagerStatePoweredOn) NSLog(@"CBCentralManagerStatePoweredOn"); //this is what gets logged when I run it on an iPhone 5
if ([manager state] == CBCentralManagerStateResetting) NSLog(@"CBCentralManagerStateResetting");
if ([manager state] == CBCentralManagerStateUnauthorized) NSLog(@"CBCentralManagerStateUnauthorized");
if ([manager state] == CBCentralManagerStateUnknown) NSLog(@"CBCentralManagerStateUnknown");
if ([manager state] == CBCentralManagerStateUnsupported) NSLog(@"CBCentralManagerStateUnsupported");
}