EmphaticArmPump
EmphaticArmPump

Reputation: 774

Check if Bluetooth is Enabled?

I just want to do a simple check of whether bluetooth is enabled on the device or not.

I don't want to change the status from inside an app (or at all), use private API's, jailbreak a device, or do anything that would cause Apple to reject an app.

All I want is to know whether bluetooth is turned on or not.

Can anyone shed any light on this? Is there any Apple-allowed way to do this?

I am fully aware, after reading countless posts and documentation that Apple is very restrictive when it comes to Bluetooth (among other things).

If you are only able to contribute to this question with a link to documentation and/or some snide remark about learning objective-c, reading documentation, etc., then please don't respond.

Upvotes: 7

Views: 16733

Answers (5)

Chris Maddern
Chris Maddern

Reputation: 767

You can now check this using the CBCentralManager in iOS 7 and initialize it with the CBCentralManagerOptionShowPowerAlertKey option set.

The CBCentralManagerOptionShowPowerAlertKey key, which can be passed to the initWithDelegate:queue:options: method on CBCentralManager which will cause iOS to start the Central Manager & not prompt the user to enable bluetooth.

Posted here: http://chrismaddern.com/determine-whether-bluetooth-is-enabled-on-ios-passively/

Upvotes: 4

Hsm
Hsm

Reputation: 1540

For iOS9+, you can check my answer here.

#import <CoreBluetooth/CoreBluetooth.h>

@interface ShopVC () <CBCentralManagerDelegate>

@property (nonatomic, strong) CBCentralManager *bluetoothManager;

@end

@implementation ShopVC

- (void)viewDidLoad {
    [super viewDidLoad];

    if(!self.bluetoothManager)
    {
        NSDictionary *options = @{CBCentralManagerOptionShowPowerAlertKey: @NO};
        self.bluetoothManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil options:options];
    }
}

#pragma mark - CBCentralManagerDelegate

- (void)centralManagerDidUpdateState:(CBCentralManager *)central
{
    NSString *stateString = nil;
    switch(self.bluetoothManager.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;
    }
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Bluetooth state"
                                                    message:stateString
                                                   delegate:nil
                                          cancelButtonTitle:@"ok" otherButtonTitles: nil];
    [alert show];
}

Upvotes: 0

BadPirate
BadPirate

Reputation: 26187

There seems to be an answer here - Using Core bluetooth framework

However, that answer will only work for iOS 5.0 and up. I haven't tested this myself, but will return and add feedback if I find that it works.

Upvotes: 3

Problematic
Problematic

Reputation: 17678

The only way I've ever found to do this is with private frameworks (like Bluetooth Manager, for one) that are only useful for Jailbroken apps... and Apple will reject any app using a private framework. I believe it's even against their ToS to do anything with bluetooth, so you're out of luck there.

Upvotes: 3

adam
adam

Reputation: 22597

Unfortunately not, the SDK does not expose Bluetooth methods.

There may be a way to do it by using undocumented methods, however we all know the problem there.

Upvotes: 2

Related Questions