Check if Bluetooth is turned on?

I just want to just check if Bluetooth is enabled on the device or not.

I don’t want to change the status from the application (or in general), use a private API, jailbreak the device or do anything that could cause Apple to reject the application.

All I want is to know if bluetooth is on or not.

Can anyone shed some light on this? Is there any way to allow Apple?

I am fully aware, having read countless messages and documentation, that Apple is very restrictive when it comes to Bluetooth (by the way).

If you can contribute to this issue with reference to the documentation and / or some comments regarding objective-c training, reading documentation, etc., then please do not respond.

+6
source share
5 answers

The only way I've ever done is private frameworks (e.g. Bluetooth Manager, for one) that are only useful for Jailbroken apps ... and Apple will reject any app using a private infrastructure. I believe that even against their ToS do anything with Bluetooth, so you're out of luck there.

+3
source

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

However, this answer will only work for iOS 5.0 and higher. I myself have not tested this, but I will come back and add a review if I find that it works.

+3
source

Unfortunately, the SDK does not provide Bluetooth methods.

There may be a way to do this using undocumented methods, but we all know about the problem.

+2
source

Now you can verify this with the CBCentralManager in iOS 7 and initialize it with the CBCentralManagerOptionShowPowerAlertKey.

The CBCentralManagerOptionShowPowerAlertKey key, which can be passed to the initWithDelegate:queue:options: method on CBCentralManager, which causes iOS to start Central Manager, rather than prompting the user to turn on Bluetooth.

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

+2
source

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]; } 
0
source

Source: https://habr.com/ru/post/892540/


All Articles