[英]iOS11 bluetooth has something strange
When I switch off the Bluetooth in setting, then I use CBCentralManager
to get the state of the Bluetooth like this: 当我关闭蓝牙设置时,我使用
CBCentralManager
来获取蓝牙状态,如下所示:
self.bluetoothManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
the system will display a alert like this: system alert 系统将显示如下警报: system alert
The current state of Bluetooth is CBManagerStatePoweredOff
. 蓝牙的当前状态为
CBManagerStatePoweredOff
。 But when I switch off the Bluetooth in control center, this alert is not show anymore even if the current state of Bluetooth is still CBManagerStatePoweredOff
. 但是,当我在控制中心中关闭Bluetooth时,即使Bluetooth的当前状态仍为
CBManagerStatePoweredOff
,也不再显示此警报。
How could I remind the user to switch on the Bluetooth in this situation? 在这种情况下,我如何提醒用户打开蓝牙?
You can remind the users by implementing the following delegate method. 您可以通过实现以下委托方法来提醒用户。
//Bluetooth state delegation
#pragma mark - CBCentralManagerDelegate
- (void)centralManagerDidUpdateState:(CBCentralManager *)central
{
NSString *stateString = nil;
switch(self.CBManager.state)
{
case CBManagerStateResetting:
stateString = @"The connection with the system service was momentarily lost, update imminent.";
break;
case CBManagerStateUnsupported:
stateString = @"The platform doesn't support Bluetooth Low Energy."; break;
case CBManagerStateUnauthorized: stateString = @"The app is not authorized to use Bluetooth Low Energy.";
break;
case CBManagerStatePoweredOff:
stateString = @"Bluetooth is currently powered off.";
break;
case CBManagerStatePoweredOn:
[self.beaconManager startMonitoringForRegion:self.museumsRegion];
[self.beaconManager startRangingBeaconsInRegion: self.museumsRegion];
break;
case CBManagerStateUnknown:
stateString = @"State unknown, update imminent.";
break;
}
NSLog(@"%@", stateString);
}
Now the user should be informed automatically. 现在应该自动通知用户。
You can disable system BlueTooth alert by using CBCentralManagerOptionShowPowerAlertKey in options dict. 您可以通过在选项dict中使用CBCentralManagerOptionShowPowerAlertKey来禁用系统蓝牙警报。
NSDictionary *options = @{CBCentralManagerOptionShowPowerAlertKey: @NO};
self.bluetoothManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil options:options];
Then you can using deleget method centralManagerDidUpdateState: to popup you custom alert. 然后,您可以使用deleget方法centralManagerDidUpdateState:弹出自定义警报。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.