gpt4 book ai didi

ios - 如何获取 CBCentralManager 检测到的信标的详细信息

转载 作者:行者123 更新时间:2023-11-28 21:53:52 25 4
gpt4 key购买 nike

我已经使用 CBCentralManager 检测到外围设备,

我用过的代码是这样的,

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self.navigationController setNavigationBarHidden: YES animated:NO];

cbMgr = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
}


- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI {


//NSLog([NSString stringWithFormat:@"%@",[advertisementData description]]);

NSLog (@"Discovered peripheral: %@", [peripheral name]);
NSLog (@"Discovered peripheral identifier: %@", [peripheral identifier]);

NSLog (@"peripheral services before connected: %@", [peripheral services]);
NSLog (@"Discovered peripheral RSSI: %@", [peripheral RSSI]);
NSLog (@"\n===============================================");

// NSLog(@"adversting data %@",[NSString stringWithFormat:@"%@",[advertisementData description]]);
}

-(void)centralManager:(CBCentralManager *)central didRetrievePeripherals:(NSArray *)peripherals{
NSLog(@"This is it!");
}

- (void)centralManagerDidUpdateState:(CBCentralManager *)central{
NSString *messtoshow;

switch (central.state) {
case CBCentralManagerStateUnknown:
{
messtoshow=[NSString stringWithFormat:@"State unknown, update imminent."];
break;
}
case CBCentralManagerStateResetting:
{
messtoshow=[NSString stringWithFormat:@"The connection with the system service was momentarily lost, update imminent."];
break;
}
case CBCentralManagerStateUnsupported:
{
messtoshow=[NSString stringWithFormat:@"The platform doesn't support Bluetooth Low Energy"];
break;
}
case CBCentralManagerStateUnauthorized:
{
messtoshow=[NSString stringWithFormat:@"The app is not authorized to use Bluetooth Low Energy"];
break;
}
case CBCentralManagerStatePoweredOff:
{
messtoshow=[NSString stringWithFormat:@"Bluetooth is currently powered off."];
break;
}
case CBCentralManagerStatePoweredOn:
{
messtoshow=[NSString stringWithFormat:@"Bluetooth is currently powered on and available to use."];
[cbMgr scanForPeripheralsWithServices:nil options:nil];
//[mgr retrieveConnectedPeripherals];

//--- it works, I Do get in this area!

break;
}

}
}

现在我想要这样的细节,
公司编号:
信标类型:
邻近 UUID:
专业:
未成年人:
测量功率:

是否有可能获得此详细信息,我已尝试使用 NSConcreteUUID 对信标进行测距,但它不返回信标数据(如预期的那样)..

最佳答案

很遗憾,您无法使用 CoreBluetooth 读取 iBeacon 信息。 Apple 阻止使用这些 API 访问 iBeacon 广告的原始数据。您可以在此处阅读有关此内容的完整详细信息:

http://developer.radiusnetworks.com/2013/10/21/corebluetooth-doesnt-let-you-see-ibeacons.html

访问其中一些数据的最佳方法是使用 CoreLocation 测距 API,但您必须事先知道信标的 PriximityUUID 才能执行此操作。我怀疑这对您不起作用的原因可能是因为您正在使用 CoreBluetooth 返回的蓝牙服务 UUID 来使用 CoreLocation 为具有给定 ProximityUUID 的信标测距。这是行不通的,因为这两个 UUID 实际上是不同的。

同样,测距是您所能做的最好的,但您将无法读取 companyId、beaconType 或 measuredPower 字段。恐怕 Apple 已彻底阻止在 iOS 上访问此信息。

关于ios - 如何获取 CBCentralManager 检测到的信标的详细信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27288211/

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