蓝牙LE请求许可?

时间:2015-04-05 11:10:55

标签: ios bluetooth bluetooth-lowenergy core-bluetooth

我有一个使用BLE的应用程序。在某些情况下,例如,当安装在iPhone 6上时,应用程序正在运行,并且没有请求使用BLE的许可。

在其他情况下,比如我的iPad Air,该应用程序开始运行,并且它不会要求用户获得BLE权限,然后BLE无效(尽管设备上的蓝牙已打开)。

Bluetooth permission

  

APP希望即使您不使用该应用,也可以向附近的蓝牙设备提供数据

下面是来自应用的关键NSBluetoothPeripheralUsageDescription或本地化Privacy - Bluetooth Peripheral Usage Description

的Info.plist数据

我不明白自动许可请求应该何时发生?

  • 如何在iOS设置中启用特定应用以使用BLE?
  • 我如何在应用内请求许可?

2 个答案:

答案 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文件中。当您的应用首次尝试使用蓝牙服务共享数据时,系统会自动显示用户授权请求。