CLBeaconRegion how to turn off a warning: turn on Bluetooth to allow * connect to accessories

We have a project that uses CoreLocation regions to monitor the iBeacon I / O area in the background of the application. CLBeaconRegion (CLRegion), CLBeacon, etc. CLLocationManager returns callbacks when the CLBeacon (iBeacon) scope is entered. This is a lightweight cover around the bluetoothManager below.

// various CLLocation delegate callback examples
- (void) locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region;
- (void) locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region;

The problem is that when the user didn’t turn on bluetooth, Iphone regularly gives a warning about the system level to "Turn on Bluetooth to allow" APP_NAME "to connect additional accessories." This happens a lot, I get it 4 times this morning as the application is running in the background. CLLocationManager may try to control these CLBeaconRegion, but bluetooth is turned off, so it cannot do this.

Another post mentions that CBCentralManager has the CBCentralManagerOptionShowPowerAlertKey property that allows you to disable this warning.

iOS CoreBluetooth passively checks if Bluetooth is turned on without prompting the user to turn on Bluetooth .

Unfortunately, I did not find a way to access the underlying Bluetooth or any CBCentralManager link to use this.

Is there a way to disable this warning for monitoring CLBeaconRegion?

enter image description here

+4
source share
1 answer

, CoreBluetooth CBCentralManager , bluetooth. , , , . , , , Bluetooth . , . , , . / bluetooth , .

// initialize in viewdidLoad, etc
_bluetoothManager =  [[CBCentralManager alloc] initWithDelegate:self queue:nil options:@{CBCentralManagerOptionShowPowerAlertKey:@NO}];


// bluetooth manager state change
- (void)centralManagerDidUpdateState:(CBCentralManager *)central
{
    NSString *stateString = nil;
    switch(central.state)
    {
        case CBCentralManagerStateResetting: stateString = @"The connection with the system service was momentarily lost, update imminent."; break;
        case CBCentralManagerStateUnsupported: stateString = @"The platform doesn't support Bluetooth Low Energy."; break;
        case CBCentralManagerStateUnauthorized: stateString = @"The app is not authorized to use Bluetooth Low Energy."; break;
        case CBCentralManagerStatePoweredOff: stateString = @"Bluetooth is currently powered off."; break;
        case CBCentralManagerStatePoweredOn: stateString = @"Bluetooth is currently powered on and available to use."; break;
        default: stateString = @"State unknown, update imminent."; break;
    }

    if(_bluetoothState != CBCentralManagerStateUnknown && _bluetoothState != CBCentralManagerStatePoweredOn && central.state == CBCentralManagerStatePoweredOn){
         NSLog(@"BEACON_MANAGER: Bluetooth just enabled. Attempting to start beacon monitoring.");
        _forceRestartLM = YES; // make sure we force restart LMs on next update, since they're stopped currently and regions may not be updated to trigger it
        [self startBeaconMonitoring];
    }

    if(_bluetoothState != CBCentralManagerStateUnknown && _bluetoothState == CBCentralManagerStatePoweredOn && central.state != CBCentralManagerStatePoweredOn)    {
        NSLog(@"BEACON_MANAGER: Bluetooth just disabled. Attempting to stop beacon monitoring.");
        [self stopBeaconMonitoring];
    }
}
+3

All Articles