CBCentralManager
未检测到附近的蓝牙设备。
- (void)viewDidLoad
{
[super viewDidLoad];
_centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
_data = [[NSMutableData alloc] init];
}
- (void)centralManagerDidUpdateState:(CBCentralManager *)central
{
if (central.state == CBCentralManagerStatePoweredOn) {
NSDictionary *options = @{CBCentralManagerScanOptionAllowDuplicatesKey: @NO};
[_centralManager scanForPeripheralsWithServices:nil options:options];
NSLog(@"Scanning started");
}
if (central.state == CBCentralManagerStateUnknown) {
NSLog(@"CBCentralManagerStateUnknown");
}
if (central.state == CBCentralManagerStateResetting) {
NSLog(@"CBCentralManagerStateResetting");
}
if (central.state == CBCentralManagerStateUnsupported) {
NSLog(@"CBCentralManagerStateUnsupported");
}
if(central.state == CBCentralManagerStateUnauthorized) {
NSLog(@"CBCentralManagerStateUnauthorized");
}
if(central.state == CBCentralManagerStatePoweredOff)
{
NSLog(@"CBCentralManagerStatePoweredOff");
}
}
我已检查过状态CBCentralManagerStatePoweredOn
之后它不会调用委托方法。