我正在开发一款应用程序来获取灯塔的uuid。我也可以得到灯塔的uuid,但这是错的。甲酸是真的但是uuid是不同的。请帮我。这是我的代码。首先,我得到了很多答案,这是不可能只从核心蓝牙api。你必须要到位置服务。我正试图获得没有信标的核心蓝牙api与位置服务关闭。
- (void)centralManagerDidUpdateState:(CBCentralManager *)central
{
switch (central.state)
{
case CBCentralManagerStatePoweredOn:
{
NSDictionary *options = @{
CBCentralManagerScanOptionAllowDuplicatesKey: @YES
};
[manger scanForPeripheralsWithServices:nil
options:options];
NSLog(@"I just started scanning for peripherals");
break;
}
}
}
- (void) centralManager:(CBCentralManager *)central
didDiscoverPeripheral:(CBPeripheral *)peripheral
advertisementData:(NSDictionary *)advertisementData
RSSI:(NSNumber *)RSSI
{
strid = [NSString stringWithFormat:@"%@",[peripheral identifier]];
//D57092AC-DFAA-446C-8EF3-C81AA22815B5
NSString *uuidString = [NSString stringWithFormat:@"%@", CFUUIDCreateString(NULL, (__bridge CFUUIDRef)([[peripheral identifier] UUIDString]))];
}
- (IBAction)identifier:(UIButton *)sender {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"" message:strid delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
[alert show];
}
- (void) centralManager:(CBCentralManager *)central
didConnectPeripheral:(CBPeripheral *)peripheral
{
if (peripheral == nil)
{
NSLog(@"connect callback has nil peripheral");
} else {
NSLog(@"Connected to peripheral with identifer: %@, state: %d, name: %@, services: %@",
[peripheral identifier],
[peripheral state],
[peripheral name],
[peripheral services]);
NSLog(@"discovering services...");
peripheral = peripheral;
peripheral.delegate = (id)self;
[peripheral discoverServices:nil];
}
}
- (void) peripheral:(CBPeripheral *)peripheral
didDiscoverServices:(NSArray *)serviceUuids
{
NSLog(@"discovered a peripheral's services: %@", serviceUuids);
}
答案 0 :(得分:1)
核心蓝牙仅提供外围设备UUID ,用于识别特定的蓝牙外围设备(信标与否),并在首次检测到设备时由iOS生成。它可能会在iOS设备之间有所不同,并且可能会在重新启动设备或蓝牙后发生变化。
另一方面, iBeacon UUID 来自广告数据包信标广播,但是核心蓝牙过滤掉了来自iBeacon数据包的所有数据,遗憾的是,你无法通过核心蓝牙学习它。 / p>
我认为这是专门通过这种方式完成的,以防止开发人员在未启用位置服务或授予适当权限的情况下使用iBeacon。这符合最终用户的利益:您可能不希望应用程序在未经您明确同意的情况下访问您的GPS位置,并且与iBeacon没有什么不同。 (旁注:谷歌似乎同意,因为在Android 6.0中,它们的工作方式相同,即没有位置权限就无法访问信标数据。)