7

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.

Toon Krijthe
  • 52,876
  • 38
  • 145
  • 202
EmphaticArmPump
  • 774
  • 4
  • 7
  • 23
  • have you seen this blog post? http://carpe-cocoa.com/2009-07-29/detecting-when-bluetooth-is-disabled-with-gksession/ – Jesse Naugher Jul 11 '11 at 22:41
  • 2
    you're definitely going to get lots of help being rude and alienating anyone who might want to help. keep that up. – Jesse Naugher Jul 11 '11 at 23:44
  • @Jesse It was not at all my intention to be rude or alienating, I was simply trying to point out that the link you posted is no longer useful because we have evolved well past iOS 3.1 and so the code in the link is essentially deprecated. In any case, please accept my apologies. – EmphaticArmPump Jul 12 '11 at 18:14
  • apology accepted. :) Theres got to a be a way to do this, and I feel like it somehow goes through Bonjour, (I read a brief snippet somewhere in Apple docs how bonjour automatically goes through bluetooth?) but I've never used Bonjour, and don't really have the time to spare to delve into the low level stuff. I would check that out as a possible option though. – Jesse Naugher Jul 12 '11 at 18:45
  • possible duplicate of [How to get the status of bluetooth (ON/OFF) in iphone programatically](http://stackoverflow.com/questions/4955007/how-to-get-the-status-of-bluetooth-on-off-in-iphone-programatically) – BadPirate Sep 27 '12 at 17:57
  • Possible duplicate of [iOS - check if bluetooth is on without system alert popup to user](https://stackoverflow.com/questions/12533269/ios-check-if-bluetooth-is-on-without-system-alert-popup-to-user) – Deepraj Chowrasia Oct 31 '17 at 11:58

5 Answers5

3

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.

Community
  • 1
  • 1
BadPirate
  • 25,802
  • 10
  • 92
  • 123
3

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/

DefenestrationDay
  • 3,712
  • 2
  • 33
  • 61
Chris Maddern
  • 737
  • 5
  • 12
3

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.

Problematic
  • 17,567
  • 10
  • 73
  • 85
2

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.

adam
  • 22,404
  • 20
  • 87
  • 119
0

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];
}
Community
  • 1
  • 1
Hsm
  • 1,510
  • 17
  • 16