Detecting iBeacons with different UUIDs

2019-04-01 19:15发布

I'm trying to use UUIDs as identifiers for specific beacons (using phones in this case). I understand that major and minor are used to do this, but I'd rather use the UUID, or the identifier string.

With that being said, is there anyway to scan for beacons regardless of UUIDs with the CLBeacon API?

标签: ios ibeacon
2条回答
唯我独甜
2楼-- · 2019-04-01 19:55

As far as I know, there is no restriction in monitoring iBeacon regions with different UUID. You can do something like:

NSArray *uuids = [NSArray arrayWithObjects:@"####-####-###1", @"####-####-###2", nil];
for (NSString *uuidString in uuids) {
    CLBeaconRegion *region = [[CLBeaconRegion alloc] initWithProximityUUID:[[NSUUID alloc] initWithUUIDString:uuidString] identifier:identifier];
    region.notifyOnEntry = entry;
    region.notifyOnExit = exit;
    region.notifyEntryStateOnDisplay = YES;
    [_locationManager startMonitoringForRegion:region];
}

You just need to make sure you check for the UUID in you locationManager's delegate methods. You can use something like this:

- (void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region {
    if ([region isKindOfClass:[CLBeaconRegion class]]) {
        CLBeaconRegion *beaconRegion = (CLBeaconRegion *)region;
        NSLog(@"ProximityUUID:%@", beaconRegion.proximityUUID);
        NSLog(@"ProximityMajor:%@", beaconRegion.major);
        NSLog(@"ProximityMinorD:%@", beaconRegion.minor);
    }
}

You should see that the delegate method is called with different UUIDs.

Hope this helps.

查看更多
神经病院院长
3楼-- · 2019-04-01 19:56

On Android you can scan for all UUIDs. On iOS you cannot. See:

http://developer.radiusnetworks.com/2013/10/21/corebluetooth-doesnt-let-you-see-ibeacons.html

On iOS, CoreLocation limits you to monitoring for at most 20 different UUIDs. Ranging does not have a limit of 20, but you still must know the UUIDs ahead of time.

查看更多
登录 后发表回答