我正在尝试制作一个简单的程序,它只列出每个连接的蓝牙设备的名称。我不断收到此错误
"CBConcreteCentralManager: (some memory address) is not powered on".
我在 iPhone 4 上启用了蓝牙,我正在测试它。我在这里做错了什么?
@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