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