Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bluetooth LE ask permission?

I have an app using BLE. In some cases, for example when installed on the iPhone 6, the app is running and not asking for permission to use the BLE.

At other cases, like my iPad Air, the app starts to run, and it's not asking for user permission for BLE, and then the BLE is not working (although the bluetooth on the device is turned on).

Bluetooth permission

APP would like to make data available to nearby Bluetooth devices even when you're not using the app

Below that is the Info.plist data from the app for the key NSBluetoothPeripheralUsageDescription or localized Privacy - Bluetooth Peripheral Usage Description

I don't understand When should the auto permission request happen?

  • How can I enable specific app to use BLE in the iOS Settings?
  • How can I ask for permission inside the app?
like image 709
Curnelious Avatar asked Apr 05 '15 11:04

Curnelious


2 Answers

The case is slightly different when explicitly asking for permissions for Bluetooth. There is no method you can call to request authorization for bluetooth.You just have to include it in info.plist file.The system automatically displays a request for user authorization when your app first attempts to use Bluetooth services to share data.

like image 77
Sudhanshu Jaisani Avatar answered Oct 12 '22 23:10

Sudhanshu Jaisani


Use the following code and call the function [self detectBluetooth]; where you want to check for bluetooth connection.

#import <CoreBluetooth/CoreBluetooth.h>


#pragma mark - setUp bluetoothManager

//check bluetooth connection
- (void)detectBluetooth
{
    if(!self.bluetoothManager)
    {
        // Put on main queue so we can call UIAlertView from delegate callbacks.
        self.bluetoothManager = [[CBCentralManager alloc] initWithDelegate:self queue:dispatch_get_main_queue()] ;
    }
    [self centralManagerDidUpdateState:self.bluetoothManager]; // Show initial state
}

- (void)centralManagerDidUpdateState:(CBCentralManager *)central
{
    NSString *stateString = nil;
    switch(bluetoothManager.state)
    {
        case CBCentralManagerStateResetting:
            [self alertStatus:@"The connection with the system service was momentarily lost, update imminent." :@"update imminent" :0];
            break;

        case CBCentralManagerStateUnsupported:
            [self alertStatus:@"The platform doesn't support Bluetooth Low Energy.":@"weak Bluetooth Connection" :0];
            break;

        case CBCentralManagerStateUnauthorized:
            [self alertStatus:@"The app is not authorized to use Bluetooth Low Energy.":@"weak Bluetooth Connection" :0];
            break;
        case CBCentralManagerStatePoweredOff:
            stateString = @"Bluetooth is currently powered off.";
            [self alertStatus:@"Bluetooth is currently powered off , powered ON first.":@"No Bluetooth Connection" :0];
            break;
        case CBCentralManagerStatePoweredOn:
            stateString = @"Bluetooth is currently powered on and available to use.";
            //  [self alertStatus:@"Bluetooth is currently powered ON.":@" Bluetooth available" :0];

            break;
        default:
            stateString = @"State unknown, update imminent.";
            break;
    }

    NSLog(@"Bluetooth State %@",stateString);        
}

@end
like image 33
Nischal Hada Avatar answered Oct 12 '22 22:10

Nischal Hada