ios - 蓝牙 LE 请求许可?

标签 ios bluetooth bluetooth-lowenergy core-bluetooth

我有一个使用 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/

    相关文章:

    c# - DeviceInformation PairAsync 在 WPF 中不起作用

    java - 为什么 Java TinyB 看不到 hcitool 看到的相同设备?

    c - 如何在 Linux x86 上使用 C 语言对蓝牙 LE 设备进行编程?

    ios - 如何使用 Objective C 增加 UItableView 中的 UIView 高度?

    android - 发送PCL命令到蓝牙打印机

    Android.bluetooth.IBluetooth.createBond() 未在 4.2.1 中找到,但适用于早期操作系统版本

    Android 手机从蓝牙更改为 BLE 后无法连接树莓派

    ios - 出现错误 : "_OBJC_CLASS_$__TtC10ChartsDemo12XYMarkerView" in Charts,

    ios - 获取 UITextField.placeHolder 属性的前景色?

    ios - present(_:animated:completion :)在Swift 3中不起作用