iOS 7 で提供される Multipeer Connectivity フレームワークに取り組んでいます。CBCentralManager クラスを持つ CoreBluetooth Framework を使用して、Bluetooth の状態を確認しようとしています。次のコード スニペットを使用しています。
//in viewDidLoad
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:FALSE], CBCentralManagerScanOptionAllowDuplicatesKey, nil];
NSMutableArray * discoveredPeripherals = [NSMutableArray new];
self.bluetoothManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
self.bluetoothManager.delegate = self;
[self.bluetoothManager scanForPeripheralsWithServices:discoveredPeripherals options:options];
[self.bluetoothManager stopScan];
//CBCentralManager delegate method
- (void)centralManagerDidUpdateState:(CBCentralManager *)central
{
// You should test all scenarios
if (central.state != CBCentralManagerStatePoweredOn)
{
return;
}
if (central.state == CBCentralManagerStatePoweredOn)
{
// Scan for devices
NSLog(@"Bluetooth On");
}
}
デバイスのバージョンに関係なく、iOS 7 の一般的な Bluetooth 状態を確認したい。脱獄やサードパーティのクラスを使用しない他の解決策はありますか? 誰でもこれで私を助けてもらえますか?
ありがとう。