[英]iOS11 bluetooth has something strange
當我關閉藍牙設置時,我使用CBCentralManager
來獲取藍牙狀態,如下所示:
self.bluetoothManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
系統將顯示如下警報: system alert
藍牙的當前狀態為CBManagerStatePoweredOff
。 但是,當我在控制中心中關閉Bluetooth時,即使Bluetooth的當前狀態仍為CBManagerStatePoweredOff
,也不再顯示此警報。
在這種情況下,我如何提醒用戶打開藍牙?
您可以通過實現以下委托方法來提醒用戶。
//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);
}
現在應該自動通知用戶。
您可以通過在選項dict中使用CBCentralManagerOptionShowPowerAlertKey來禁用系統藍牙警報。
NSDictionary *options = @{CBCentralManagerOptionShowPowerAlertKey: @NO};
self.bluetoothManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil options:options];
然后,您可以使用deleget方法centralManagerDidUpdateState:彈出自定義警報。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.