3

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

我试着这样做:

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

if (manager.state == CBCentralManagerStatePoweredOn ) {

      //go ahead with GameKit
}

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

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

4

2 回答 2

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];

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

于 2012-07-18T21:46:07.840 回答
0

您可以通过此链接找到您问题的答案。看看这个。

已编辑

您是否查看过Game Kit Framework 参考资料

据苹果称:

Game Kit 使您的应用程序能够在两个设备之间创建蓝牙连接。

已编辑

然后试试这个项目。https://github.com/sergiomtzlosa/MultiContactsSelector-ios

于 2012-07-18T05:50:24.990 回答