【问题标题】:iBeacons Transmit and Receive UUIDiBeacons 发送和接收 UUID
【发布时间】:2014-06-15 09:17:53
【问题描述】:

我很困惑。

我使用 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 是不同的——在我看来应该是一样的。

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

【问题讨论】:

    标签: ios uuid core-bluetooth ibeacon


    【解决方案1】:

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

    尽管在这两个字段中都使用了 UUID 一词,但它们完全不同。 CBCentralManager 可以看到的字段只是 iOS 生成的会话特定标识符。如果您以后使用相同的 API 来发现相同的设备,它将是不同的值。

    很遗憾,无法使用CoreBluetooth API 来读取 iBeacon 标识符。有关原因的更多信息,请参阅this blog post

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-04-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-14
      相关资源
      最近更新 更多