在iOS中检查蓝牙状态

我有一个应用程序(我不会提交这个应用程序到苹果应用程序商店)使用我要检查是否蓝牙打开。 如果打开,那么我必须显示一个警报。

- (void)centralManagerDidUpdateState:(CBCentralManager *)central{ switch (central.state) { case CBCentralManagerStatePoweredOn:{ //alert view break; } } 

而在viewdidload我这样做

  CBCentralManager * manager = [[CBCentralManager alloc] initWithDelegate:self queue:nil]; 

但是这不适用于使用ios 5.1的ipad2。

问题是central.state始终为空。

我想要从ios 3.0到ios 6 beta的相同场景。 有没有用于检查蓝牙状态的通用代码。

任何可能的代码是受欢迎的,即使代码与私人API。

CBCentralManager用于使用蓝牙智能(蓝牙4.0中的低能量部分)。 这是最近才在iOS / OS X设备中引入的新技术。 目前的支持是在iPhone 4s和新的iPad。 iPad 2不支持这项技术。 此外, CBCentralManager只能从iOS 5及以上版本获得。

如果你想检查传统的蓝牙状态,你将不得不寻找另一种方式来做到这一点。

在你的情况下, central.state实际上应该等于CBCentralManagerStateUnsupported

你想看看BluetoothManager API。 BluetoothManager.framework是该API所在的私有框架。您可以从您的Xcode项目中链接到它,或者使用dlopendynamic地打开它( "/System/Library/PrivateFrameworks/BluetoothManager.framework/BluetoothManager" )。

重要的电话会是

 - (BOOL)powered; - (BOOL)enabled; - (BOOL)setPowered:(BOOL)arg1; - (BOOL)setEnabled:(BOOL)arg1; 

要获得BluetoothManager的实例,请使用以下命令:

 BluetoothManager* mgr = [BluetoothManager sharedInstance]; 

我也没有得到运行iOS7的iPhone 4上的CBCentralManagerStateUnsupported。 我打开了一个与苹果的bug票。

http://openradar.appspot.com/15564675是雷达

https://github.com/deadfalkon/btLeState存储库