2014-04-29 76 views
0

我很困惑。iBeacons发送和接收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是不同的 - 在我看来应该是相同的。

- >我做错了什么/明白错误?

回答

1

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

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

不幸的是,不可能使用CoreBluetooth API读取iBeacon标识符。有关为什么参见this blog post的更多信息。

+0

谢谢你的回答!这些现在很清楚。 – Marco