【问题标题】:Bluetooth LE ask permission?蓝牙 LE 请求许可?
【发布时间】:2015-06-09 23:42:23
【问题描述】:

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

在其他情况下,例如我的 iPad Air,应用程序开始运行,并且它没有请求用户对 BLE 的许可,然后 BLE 不工作(尽管设备上的蓝牙已打开)。

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

下面是来自应用程序的 Info.plist 数据,用于键 NSBluetoothPeripheralUsageDescription 或本地化 Privacy - Bluetooth Peripheral Usage Description

我不明白什么时候应该发生自动权限请求?

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

【问题讨论】:

  • 你找到答案了吗?

标签: ios bluetooth bluetooth-lowenergy core-bluetooth


【解决方案1】:

当明确请求蓝牙权限时,情况略有不同。您无法调用任何方法来请求蓝牙授权。您只需将其包含在 info.plist 文件中即可。当您的应用首次尝试使用蓝牙服务共享数据时,系统会自动显示用户授权请求。

【讨论】:

  • 我们在我们的应用程序中发现,这样做并不能让我们的蓝牙信标使用成功(至少在 iOS 12 中,在 iOS 13 中可能更是如此)。我们使用 CBPeripheralManager 和它的委托,但似乎我们也可能需要开始使用 CBCentralManager;没试过。
【解决方案2】:

使用以下代码并调用您要检查蓝牙连接的函数[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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-10-26
    • 1970-01-01
    • 2013-10-25
    • 1970-01-01
    • 2018-03-02
    • 2020-12-14
    • 2017-04-27
    相关资源
    最近更新 更多