接続されているすべてのBluetooth デバイスの名前を一覧表示するだけの簡単なプログラムを作成しようとしています。このエラーが発生し続けます
"CBConcreteCentralManager: (some memory address) is not powered on".
これをテストしているiPhone 4でBluetoothを有効にしました。ここで何が間違っていますか?
@interface ViewController ()
@property (strong, nonatomic) CBCentralManager *centralManager;
@end
@implementation ViewController
- (void)viewDidLoad{
[super viewDidLoad];
self.centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:dispatch_get_main_queue()];
[self.centralManager retrieveConnectedPeripherals];
}
- (void)centralManager:(CBCentralManager *)central didRetrieveConnectedPeripherals:(NSArray *)peripherals{
for (CBPeripheral *a in peripherals){ //print all of the names
NSLog(a.name);
}
}
- (void)centralManagerDidUpdateState:(CBCentralManager *)central{
NSLog([NSString stringWithFormat:@"%d", [central state]]); //prints 2, which is CBCentralManagerStateUnsupported
}
//irrelevant methods not shown
@end