Disable Warning Dialog if Bluetooth is powered off iOS

后端 未结 2 2010
死守一世寂寞
死守一世寂寞 2020-12-09 11:43

My ios application uses bluetooth to connect to an accessory. If Bluetooth is not enabled, a popup appears asking me to activate.

相关标签:
2条回答
  • 2020-12-09 12:19

    If you are connecting to accessory devices, you might also be using the CBPeripheralManager instead of the CBCentralManager. Tuck me some time to figure this out, because I was using a sdk and couldn't tell what it actually did. But in this case you have to suppress the alert on the peripheral manager. Once the flag is set it will be valid for all other instances of the CBCentralManager or the CBPeripheralManager respectively. Im my case, the only reason I instantiated the CBPeripheralManager at all was to set the flag.

    @property CBPeripheralManager *pManager;
    
    *peripheralManager = [[CBPeripheralManager alloc]initWithDelegate:nil queue:nil options:@{CBPeripheralManagerOptionShowPowerAlertKey:@NO}];
    

    Note that you have to assign the instance to a property or it won't work.

    0 讨论(0)
  • 2020-12-09 12:26

    I got the following response from an apple developer : In iOS7, the CBCentralManagerOptionShowPowerAlertKey option lets you disable this alert.

    If you have a CBCentralManager, then when you initialise it, you can use the method -[CBCentralManager initWithDelegate:queue:options]

    Example:

    In my .h file, I have a CBCentralManager * manager.

    In my .m file:

    NSDictionary *options = @{CBCentralManagerOptionShowPowerAlertKey: @NO};
        
    _manager = [[CBCentralManager alloc] initWithDelegate:self queue:nil options:options];
        
    [_manager scanForPeripheralsWithServices:nil options:options];
    

    With this code, the warning no longer appears. I hope that helps!

    0 讨论(0)
提交回复
热议问题