2

近くにあるすべての Bluetooth デバイスを、その名前、UUID、RSSI、現在地からのおおよその距離とともに一覧表示する iOS アプリを作成したいと考えています。CoreBlueTooth API を調査し、中央マネージャーを作成しましたが、役に立ちません。以下は私がこれまでに行ったことです。30 秒間スキャンした後、近くにデバイスが見つかりませんが、デバイス設定と Bluetooth セクションに移動すると、デバイスのリストが表示されます。ここで何が間違っているのでしょうか?

- (void)viewDidAppear:(BOOL)animated {
    self.centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
}

- (void)centralManagerDidUpdateState:(CBCentralManager *)central {
    if (central.state != CBCentralManagerStatePoweredOn) {
        return;
    }

    [self scan];
}


- (void)scan
{
    self.anAcivityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    self.anAcivityIndicator.center = self.view.center;
    [self.anAcivityIndicator startAnimating];
    [self.view addSubview:self.anAcivityIndicator];

    [NSTimer scheduledTimerWithTimeInterval:30.0 target:self selector:@selector(stopScanning) userInfo:nil repeats:NO];
    [self.centralManager scanForPeripheralsWithServices:nil options:@{CBCentralManagerScanOptionAllowDuplicatesKey : @YES }];
    NSLog(@"Scanning started");
}


- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI {
    NSString *aBeaconName = peripheral.name;
    NSUUID *anIdentifier = peripheral.identifier;
    if (aBeaconName && anIdentifier) {
        [self.beaconUUID setObject:anIdentifier forKey:aBeaconName];
    }

}

- (void)stopScanning {
    [self.centralManager stopScan];

    if ([self.beaconUUID count] > 0) {
        [self.tableView reloadData];
    } else {
        UIAlertView *anAlertView = [[UIAlertView alloc] initWithTitle:@"No Data" message:@"No beacon found!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [anAlertView show];
    }
}

- (void)alertView:(UIAlertView *)iAlertView clickedButtonAtIndex:(NSInteger)iButtonIndex {
    [self.navigationController popToRootViewControllerAnimated:YES];
}
4

3 に答える 3

2

iOS 7 のCoreLocationフレームワークの機能強化に注目するかもしれません。NDAに違反しない限り、それ以上のことは言えませんが、道案内に役立つビーコンがいくつか見つかると思います。:)

于 2013-06-27T02:04:25.320 に答える
1

まず、iOS の設定で、すべての Bluetooth デバイス (BLE と非 BLE) を表示します。コードによると、ペリフェラル モードで動作する Bluetooth Low Energy デバイスのみを検出できます。ペリフェラル モードで動作する BLE デバイスがリストに 1 つあることを確認してください (たとえば、iBeacon)。通常、セントラル モードまたはペリフェラル モードで BLE デバイスを検出するには、従来の BT フレームワークを使用します。iBeacon デバイスの場合は、CoreLocation フレームワークを適用することをお勧めします。

于 2015-01-13T10:48:44.017 に答える
1

BLE は、デバイスの近接性を検出するために使用できる信号強度パラメーターを返します。コア Bluetooth から取得できる場合は、経路損失の式で使用して、最も近いデバイスを見つけることができます。

于 2020-03-07T20:29:28.383 に答える