繁体   English   中英

iBeacons发送和接收UUID

[英]iBeacons Transmit and Receive UUID

我糊涂了。

我使用CLBeaconRegion创建了一个信标,并使用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和接收的UUID是不同的-我认为应该相同。

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

问题在于,您使用CBCentralManager读取的UUID与iBeacon的ProximityUUID没有关系。

尽管在两个字段中都使用了术语UUID,但它们是完全不同的。 您可以使用CBCentralManager查看的字段只是iOS生成的特定于会话的标识符。 如果您以后使用相同的API查找相同的设备,则它将是不同的值。

不幸的是,不可能使用CoreBluetooth API读取iBeacon标识符。 有关为什么的更多信息,请参见此博客文章

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM