gpt4 book ai didi

ios - 蓝牙 LE 请求许可?

转载 作者:行者123 更新时间:2023-12-04 20:14:02 28 4
gpt4 key购买 nike

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

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

Bluetooth permission

APP would like to make data available to nearby Bluetooth devices even when you're not using the app



下面是来自应用程序的 Info.plist 数据,用于 key NSBluetoothPeripheralUsageDescription或本地化 Privacy - Bluetooth Peripheral Usage Description
我不明白什么时候应该发生自动权限请求?
  • 如何在 iOS 设置中启用特定应用程序以使用 BLE?
  • 我如何在应用程序内请求许可?
  • 最佳答案

    使用以下代码并调用函数 [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

    关于ios - 蓝牙 LE 请求许可?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29456654/

    28 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com