检查的iOS蓝牙状态 [英] Check bluetooth state in iOS
问题描述
我有一个应用程序(我不打算给这个应用程序提交给苹果的应用程序商店)使用,我想检查是否蓝牙开启。如果它被打开以后我就显示一个警告。
I have an application (I am not going to submit this app to apple app store) using which I want to check whether bluetooth is turned on. If it is turned on then I have to display an alert.
- (void)centralManagerDidUpdateState:(CBCentralManager *)central{
switch (central.state) {
case CBCentralManagerStatePoweredOn:{
//alert view
break;
}
}
而在 viewDidLoad中
我不喜欢这样。
CBCentralManager * manager = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
但这不是在ipad2的与iOS 5.1的工作。
but this is not working in ipad2 with ios 5.1.
问题是 central.state
总是空。
我希望同样的场景,从IOS 3.0工作到iOS 6测试版。是否有任何共同code检查蓝牙状态。
I want the same scenario to work from ios 3.0 to ios 6 beta. Is there any common code for checking bluetooth state.
任何可能的code是值得欢迎的,甚至code。与私有API。
Any possible code is welcome, even code with private api.
推荐答案
CBCentralManager
是通过蓝牙智能(蓝牙4.0低能量的一部分)。这只是最近的iOS / OS X设备引入了新的技术。目前支持在iPhone 4S和新iPad。而iPad 2不具备这种技术的支持。另外, CBCentralManager
只能从的iOS 5及以上。
CBCentralManager
is for using Bluetooth Smart (the Low Energy part in Bluetooth 4.0). This is a new technology only recently introduced in iOS / OS X devices. Current support is in iPhone 4s and the new iPad. The iPad 2 does NOT have support for this technology. Also the CBCentralManager
is only available from iOS 5 and up.
如果您要检查传统蓝牙状态,你将不得不寻找另一种方式来做到这一点。
If you want to check traditional Bluetooth state you will have to find another way to do that.
在你的情况 central.state
实际上应该等于 CBCentralManagerStateUnsupported
。
In your case central.state
should actually equal CBCentralManagerStateUnsupported
.
这篇关于检查的iOS蓝牙状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!