We have a project that is using CoreLocation regions to monitor iBeacon region entering/exiting in the app background. CLBeaconRegion (CLRegion), CLBeacon, etc. CLLocationManager returns callbacks when a CLBeacon (iBeacon) region is entered. It is a light wrapper around a bluetoothManager underneath.
// 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 we're having is that when a user does not have bluetooth turned on, the Iphone issues a system level warning on a regular basis to 'Turn On Bluetooth to Allow "APP_NAME" to Connect ot Accessories'. This happens a lot, I've got it 4 times this morning already as the app runs in the background. CLLocationManager may be attempting to monitor those CLBeaconRegion, but bluetooth is off so it can't do this.
Another post, mentions that CBCentralManager has a property, CBCentralManagerOptionShowPowerAlertKey, that allows disabling this warning.
Unfortunately I've found no way to access underlying bluetooth, or any CBCentralManager reference to use this.
Is there any way to disable this warning for CLBeaconRegion monitoring?
I worked out a solution that uses CoreBluetooth and
CBCentralManager
to detect, stop, and start bluetooth usage. Below is the majority of the code, plus an initial check to see if it is on before starting. It works to suppress the error prompt by guaranteeing beacons are not being used when bluetooth is off. If it is disabled, beacons are stopped. The warning thus goes away. We're unable to actually enable/disable bluetooth programmatically unfortunately.