如何检测我的苹果设备是否支持蓝牙低功耗

时间:2012-11-27 13:24:22

标签: ios bluetooth bluetooth-lowenergy

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

3 个答案:

答案 0 :(得分:14)

假设您有一个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代理更新,然后在您的应用中采取相应的操作。

答案 1 :(得分:3)

另一种选择是检查设备是否支持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");
}

答案 2 :(得分:1)

寻找CoreBluetooth.framework ...... CBCentralManagerStateUnsupported