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).
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?
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With