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

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

假设您有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委托更新,然后在您的应用程序中采取适当的操作。

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

迅速:

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

目标C:

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

寻找CoreBluetooth.framework … CBCentralManagerStateUnsupported