在没有BluetoothManager的iOS 5上检查蓝牙是否已禁用

Reg*_*an 3 iphone cocoa-touch gamekit ios core-bluetooth

我已经看到,在iOS 5中,CoreBluetooth提供了检查蓝牙是否被禁用的功能.从我所看到的文档来看,它显然是针对蓝牙外设使用的.但是,我正在尝试检查蓝牙是否已打开,因为我正在使用GameKit(GKPeerPickerController),如果未启用蓝牙连接,将无休止地搜索,这是一个问题.

我尝试这样做:

CBCentralManager * manager = [[CBCentralManager alloc] init];

if (manager.state == CBCentralManagerStatePoweredOn ) {

      //go ahead with GameKit
}
Run Code Online (Sandbox Code Playgroud)

这不起作用,并且manager.state始终等于null.我在这做错了什么?或者,有没有更好的方法来检查iPhone上的蓝牙状态?

编辑:我不想调用任何私有API,因为我将这个应用程序提交到应用程序商店.我已经编辑了我的问题标题以澄清这一点.

Reg*_*an 5

好的,我发现这样做:

NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:FALSE], CBCentralManagerScanOptionAllowDuplicatesKey, nil];
NSMutableArray * discoveredPeripherals = [NSMutableArray new];
CBCentralManager * manager = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
[manager scanForPeripheralsWithServices:discoveredPeripherals options:options];
[manager stopScan];
Run Code Online (Sandbox Code Playgroud)

如果蓝牙关闭,系统将弹出一个警报视图,提供打开蓝牙的选项.否则,如果找到外设,它将调用相应的委托方法,但如果该实现中没有任何内容,则无需担心它.