【发布时间】:2012-11-27 13:24:22
【问题描述】:
是否有一个 API 可以让我判断运行我的应用程序的 Apple 设备(iPad/iPod/iPhone)是否支持低功耗蓝牙 (BTLE)。
【问题讨论】:
标签: ios bluetooth bluetooth-lowenergy
是否有一个 API 可以让我判断运行我的应用程序的 Apple 设备(iPad/iPod/iPhone)是否支持低功耗蓝牙 (BTLE)。
【问题讨论】:
标签: ios bluetooth bluetooth-lowenergy
假设您有一个 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?
另一个选项是检查设备是否支持 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");
}
【讨论】:
寻找CoreBluetooth.framework... CBCentralManagerStateUnsupported等
【讨论】: