在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项目中链接到它,或者使用dlopen
dynamic地打开它( "/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票。
- locationManager:rangingBeaconsDidFailForRegion:withError:kCLErrorDomain 16
- 方法captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer :( CMSampleBufferRef)sampleBuffer fromConnection只调用了几次
- SWIFT – BLE通信
- 如何触发核心蓝牙状态保存和恢复
- 使用BluetoothManager私有框架获取蓝牙的MAC地址
- Android和iPhone之间通过蓝牙文件传输?
- SPPconfiguration文件蓝牙iOS
- 我需要知道什么规格来开发蓝牙(AVRCP 1.4)iPhone应用程序
- 核心蓝牙广告并在后台扫描