How can I detect if my apple device supports Bluetooth Low Energy

前端 未结 3 971
你的背包
你的背包 2020-12-16 15:31

Is there an API via which I can tell if the Apple device (iPad/iPod/iPhone) that my App is running on supports Bluetooth Low Energy (BTLE).

相关标签:
3条回答
  • 2020-12-16 15:42

    Assuming you have an iOS5 or iOS6 device and that you have a CBCentralManager object, you can check its CBCentralManagerState with the following:

    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.";
    
    }
    

    You'll want to watch for centralManagerDidUpdateState:central delegate updates as well, then take the appropriate action in your app.

    0 讨论(0)
  • 2020-12-16 15:43

    Another option is to check whether the device supports iBeacons. This is because the device must support Bluetooth LE (i.e. Bluetooth 4) in order to find an iBeacon. Just import CoreLocation and use the following:

    Swift:

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

    Objective C:

    if ([CLLocationManager isMonitoringAvailableForClass:[CLBeaconRegion class]]){
        NSLog(@"Bluetooth LE is supported");
    }
    
    0 讨论(0)
  • 2020-12-16 15:48

    Look for CoreBluetooth.framework... CBCentralManagerStateUnsupported, etc.

    0 讨论(0)
提交回复
热议问题