我有一个使用BLE的应用程序。在某些情况下,例如,当安装在iPhone 6上时,应用程序正在运行,并且没有请求使用BLE的许可。
在其他情况下,比如我的iPad Air,该应用程序开始运行,并且它不会要求用户获得BLE权限,然后BLE无效(尽管设备上的蓝牙已打开)。
APP希望即使您不使用该应用,也可以向附近的蓝牙设备提供数据
下面是来自应用的关键NSBluetoothPeripheralUsageDescription
或本地化Privacy - Bluetooth Peripheral Usage Description
我不明白自动许可请求应该何时发生?
答案 0 :(得分:0)
使用以下代码并调用要检查蓝牙连接的函数[self detectBluetooth];
。
#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
答案 1 :(得分:0)
当明确要求蓝牙许可时,情况略有不同。您无法调用任何方法来请求蓝牙授权,只需将其包含在info.plist文件中。当您的应用首次尝试使用蓝牙服务共享数据时,系统会自动显示用户授权请求。