如何检测我的苹果设备是不是支持蓝牙低功耗
Posted
技术标签:
【中文标题】如何检测我的苹果设备是不是支持蓝牙低功耗【英文标题】:How can I detect if my apple device supports Bluetooth Low Energy如何检测我的苹果设备是否支持蓝牙低功耗 【发布时间】:2012-11-27 13:24:22 【问题描述】:是否有一个 API 可以让我判断运行我的应用程序的 Apple 设备(iPad/iPod/iPhone)是否支持低功耗蓝牙 (BTLE)。
【问题讨论】:
【参考方案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
委托更新,然后在您的应用中采取适当的操作。
【讨论】:
如果我得到CBCentralManagerStatePoweredOn
或CBCentralManagerStatePoweredOff
是否保证支持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等
【讨论】:
以上是关于如何检测我的苹果设备是不是支持蓝牙低功耗的主要内容,如果未能解决你的问题,请参考以下文章
混合APP低功耗蓝牙项目解析数据可能用到的一些小方法---ble