gpt4 book ai didi

ios - 如何使用 iOS 应用程序识别 BTLE 设备的名称、UUID、RSSI 和大概距离

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:09:42 28 4
gpt4 key购买 nike

我想编写一个 iOS 应用程序,列出所有附近的蓝牙设备及其名称、UUID、RSSI 和与我当前位置的大概距离。我探索了 CoreBlueTooth API 并创建了一个中央管理器,但这没有帮助。以下是我到目前为止所做的。扫描 30 秒后,我没有在附近找到任何设备,但是当我转到设备设置和蓝牙部分时,它会显示设备列表。知道这里可能出了什么问题吗?

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

最佳答案

您可能会查看 CoreLocation 的增强功能iOS 7 的框架。如果不违反保密协议(protocol),我不能说更多,但我认为您可能会找到一些有用的信标来指导您。 :)

关于ios - 如何使用 iOS 应用程序识别 BTLE 设备的名称、UUID、RSSI 和大概距离,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17332354/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com