iOS - check if bluetooth is on without system alert popup to user

Oleg Shanyuk picture Oleg Shanyuk · Sep 21, 2012 · Viewed 19k times · Source

This code allows to determine current bluetooth status:

CBCentralManager* testBluetooth = [[CBCentralManager alloc] initWithDelegate:nil queue: nil];


switch ([testBluetooth state]) {....}

But, when [[CBCentralManager alloc] init...] happens, system popups an alert to user, if bluetooth is off.

Is there any way to check bluetooth status without disturbing my users?

Answer

Ali Abbas picture Ali Abbas · Oct 21, 2013

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

If you havea a CBCentralManager when you initialise it, you can use the method initWithDelegate:queue:options

Example:

In my .h file i have a CBCentralManager * manager

In .m file :

NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:NO], CBCentralManagerOptionShowPowerAlertKey, nil];

_manager = [[CBCentralManager alloc] initWithDelegate:self queue:nil options:options];

[_manager scanForPeripheralsWithServices:nil options:nil];

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