持续显示"打开蓝牙以允许应用程序连接到配件"在ios的背景中的警报消息

时间:2015-12-07 11:08:01

标签: ios bluetooth core-bluetooth

我在我的应用程序中使用iBeacon技术。我在应用程序中检查用户是否已启用或禁用蓝牙,并且我已在下面编写代码。

 - (void)viewDidLoad 
 {
  [super viewDidLoad];
  _bluetoothManager =  [[CBCentralManager alloc] initWithDelegate:self queue:nil options:nil];
}

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

enter image description here

问题:以上警告消息经常在后台提示,或者当其他应用程序打开时,即使我已杀死该应用程序。我想显示此默认警报消息,但仅在用户打开应用程序时显示。

有人能为我提供解决方案吗?

1 个答案:

答案 0 :(得分:6)

self.bluetoothManager = [[CBCentralManager alloc] initWithDelegate:self
                                                             queue:nil
                                                           options:@{CBCentralManagerOptionShowPowerAlertKey: @NO}];

这可能会隐藏系统弹出窗口。