Question

I'm confused.

I created a Beacon using a CLBeaconRegion and advertising it with the 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];
    }
}

And I was able to receive the iBeacon with the CBCentralManager:

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);
}

This basically works. But the transmitted and the received UUID's are different - which in my opinion should be the same.

--> What did I do wrong / understand wrong??

Était-ce utile?

La solution

The problem is that the UUID you read with CBCentralManager has nothing to do with the iBeacon's ProximityUUID.

Despite the use of the term UUID in both fields, they are completely different. The field you can see with CBCentralManager is just a session-specific identifier generated by iOS. If you use the same API to discover the same device at a later time, it will be a different value.

Unfortunately, it is not possible to use CoreBluetooth APIs to read iBeacon identifiers. For more information about why see this blog post.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top