我糊涂了。

我使用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生成的特定于 session 的标识符。如果以后使用相同的API查找相同的设备,则它将是不同的值。

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

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

10-12 00:12
查看更多