ios - iBeacons 发送和接收 UUID

标签 ios uuid core-bluetooth ibeacon

我很困惑。

我使用 CLBeaconRegion 创建了一个 Beacon,并使用 CBPeripheralManager 对其进行广告:

- (void)startTransmitting:(NSUUID*)uuid major:(NSInteger)major minor:(NSInteger)minor identifier:(NSString*)identifier {
    self.beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:uuid
                                                                major:major
                                                                minor:minor
                                                           identifier:identifier];

    self.beaconPeripheralData = [self.beaconRegion peripheralDataWithMeasuredPower:nil];
    self.peripheralManager = [[CBPeripheralManager alloc] initWithDelegate:self
                                                                     queue:nil
                                                                   options:nil];
}

-(void)peripheralManagerDidUpdateState:(CBPeripheralManager *)peripheral {
    if (peripheral.state == CBPeripheralManagerStatePoweredOn) {
        NSLog(@"Powered On");
        [self.peripheralManager startAdvertising:self.beaconPeripheralData];
    } else if (peripheral.state == CBPeripheralManagerStatePoweredOff) {
        NSLog(@"Powered Off");
        [self.peripheralManager stopAdvertising];
    }
}

而且我能够通过 CBCentralManager 接收 iBeacon:

self.centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
[self.centralManager scanForPeripheralsWithServices:nil options:nil];

- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI {
    [self.peripherals addObject:peripheral];
    NSLog(@"New Peripheral found and added... %@", peripheral);
}

这基本上有效。但是传输的和接收到的 UUID 是不同的——在我看来应该是相同的。

--> 我做错了什么/理解错了什么??

最佳答案

问题是您使用 CBCentralManager 读取的 UUID 与 iBeacon 的 ProximityUUID 无关。

尽管在两个领域都使用术语 UUID,但它们是完全不同的。您可以使用 CBCentralManager 看到的字段只是 iOS 生成的特定于 session 的标识符。如果您以后使用相同的 API 发现相同的设备,它将是不同的值。

不幸的是,无法使用 CoreBluetooth API 读取 iBeacon 标识符。有关原因的更多信息,请参阅 this blog post .

关于ios - iBeacons 发送和接收 UUID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23364601/

相关文章:

ios - 如何在 CollectionView 中创建这个布局

swift - 在 ios 8 中使用蓝牙发送到外设的数据量

ios - 如何使 splitViewController 在所有设备上表现相同

iphone - 在 localizable.strings 中添加富文本

javascript - 从特定 Javascript 生成 v4 UUID

MySQL:使用 UUID(字节串)作为主键的查询不起作用

ios - Core Bluetooth CBCentralManager 在 ipad2 上总是报告状态为未知

ios - Objective C 中的蓝牙配对与连接

ios - AVAudioPlayer 始终为 null,其 isPlaying 属性始终为 false。播放时文件混合

ios - NSUUID 重复机会来自不同的设备。