CLBeaconRegion,如何closures警告:打开蓝牙允许*连接到附件

我们有一个使用CoreLocation地区来监控iBeacon地区进入/退出应用程序背景的项目。 CLBeaconRegion(CLRegion),CLBeacon等。当inputCLBeacon(iBeacon)区域时,CLLocationManager返回callback。 这是一个在下面的蓝牙pipe理器周围的轻包装。

// 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; 

我们遇到的问题是,当用户没有开启蓝牙function时,Iphone会定期发出系统级警告,将“打开蓝牙以允许”APP_NAME“连接其他配件”。 这发生了很多,我已经在今天早上4次,因为应用程序在后台运行。 CLLocationManager可能试图监视那些CLBeaconRegion,但蓝牙已closures,所以它不能这样做。

另一篇文章提到CBCentralManager有一个属性,CBCentralManagerOptionShowPowerAlertKey,允许禁用这个警告。

iOS CoreBluetooth被动地检查蓝牙是否启用,而不提示用户打开蓝牙

不幸的是,我发现没有办法访问底层的蓝牙,或任何CBCentralManager引用来使用它。

有什么办法来禁用CLBeaconRegion监视此警告?

在这里输入图像说明

我制定了一个使用CoreBluetooth和CBCentralManager来检测,停止和启动蓝牙使用的解决scheme。 下面是大部分的代码,再加上一个初始检查,看它是否在开始之前。 它通过保证在蓝牙closures时没有使用信标来抑制错误提示。 如果禁用,则停止信标。 警告因此消失。 我们不能实际启用/禁用蓝牙编程不幸的。

 // 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]; } }