【问题标题】:How can I detect if my apple device supports Bluetooth Low Energy如何检测我的苹果设备是否支持蓝牙低功耗
【发布时间】:2012-11-27 13:24:22
【问题描述】:

是否有一个 API 可以让我判断运行我的应用程序的 Apple 设备(iPad/iPod/iPhone)是否支持低功耗蓝牙 (BTLE)。

【问题讨论】:

    标签: ios bluetooth bluetooth-lowenergy


    【解决方案1】:

    假设您有一个 iOS5 或 iOS6 设备并且您有一个 CBCentralManager 对象,您可以使用以下命令检查其 CBCentralManagerState:

    switch ([_manager state])
    {
        case CBCentralManagerStateUnsupported:
            state = @"This device does not support Bluetooth Low Energy.";
            break;
        case CBCentralManagerStateUnauthorized:
            state = @"This app is not authorized to use Bluetooth Low Energy.";
            break;
        case CBCentralManagerStatePoweredOff:
            state = @"Bluetooth on this device is currently powered off.";
            break;
        case CBCentralManagerStateResetting:
            state = @"The BLE Manager is resetting; a state update is pending.";
            break;
        case CBCentralManagerStatePoweredOn:
            state = @"Bluetooth LE is turned on and ready for communication.";
            break;
        case CBCentralManagerStateUnknown:
            state = @"The state of the BLE Manager is unknown.";
            break;
        default:
            state = @"The state of the BLE Manager is unknown.";
    
    }
    

    您还需要注意centralManagerDidUpdateState:central 委托更新,然后在您的应用中采取适当的操作。

    【讨论】:

    • 如果我得到CBCentralManagerStatePoweredOnCBCentralManagerStatePoweredOff 是否保证支持BLE?
    【解决方案2】:

    另一个选项是检查设备是否支持 iBeacons。这是因为设备必须支持蓝牙 LE(即蓝牙 4)才能找到 iBeacon。只需导入 CoreLocation 并使用以下内容:

    斯威夫特:

    if (CLLocationManager.isMonitoringAvailable(for: CLBeaconRegion.self)){
        print("Bluetooth LE is supported")
    }
    

    目标 C:

    if ([CLLocationManager isMonitoringAvailableForClass:[CLBeaconRegion class]]){
        NSLog(@"Bluetooth LE is supported");
    }
    

    【讨论】:

    • 这对我有用。这样你就可以有一个简单的 getter,而不是尝试使用状态来做一些更复杂的模式。
    【解决方案3】:

    寻找CoreBluetooth.framework... CBCentralManagerStateUnsupported

    【讨论】:

      猜你喜欢
      • 2016-10-09
      • 1970-01-01
      • 1970-01-01
      • 2022-01-08
      • 1970-01-01
      • 2014-07-30
      • 2013-11-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多