我有一个应用程序(我不打算提交这个应用程序到苹果应用商店)使用,我想检查蓝牙是否开启。 如果它被打开,然后我要显示一个警告。
- (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测试版。 是否有检查蓝牙状态的任何公共代码。
任何可能的代码是值得欢迎的,甚至代码私有API。
CBCentralManager
是使用智能蓝牙(蓝牙4.0低能量的部分)。 这只是最近的iOS / OS X设备推出的一项新技术。 目前支持在iPhone 4S和新iPad。 而iPad 2不具备这种技术的支持。 另外, CBCentralManager
只能从iOS 5及了。
如果您想检查传统的蓝牙状态,你将不得不寻找另一种方式来做到这一点。
在你的情况central.state
实际上应该等于CBCentralManagerStateUnsupported
。
你想看看BluetoothManager
API。 该BluetoothManager.framework是,这个API住在私人框架。您可以从您的Xcode项目中链接到它,或使用dlopen
打开它( "/System/Library/PrivateFrameworks/BluetoothManager.framework/BluetoothManager"
)动态。
重要的电话会
- (BOOL)powered;
- (BOOL)enabled;
- (BOOL)setPowered:(BOOL)arg1;
- (BOOL)setEnabled:(BOOL)arg1;
要获得实例BluetoothManager
,使用:
BluetoothManager* mgr = [BluetoothManager sharedInstance];
I'm还没有运行iOS7的iPhone 4入门CBCentralManagerStateUnsupported。 我开了一个bug票与苹果。
http://openradar.appspot.com/15564675是雷达
和https://github.com/deadfalkon/btLeState库