Yes you can. To do that you don't have to keep property self.beaconRegion you just create as many as you like and start monitor and start ranging for it, for example this is how I do that:
//Reion 1
CLBeaconRegion *region = [[CLBeaconRegion alloc] initWithProximityUUID:uuid major:major minor:minor identifier:identifier];
region.notifyOnEntry = YES;
region.notifyOnExit = YES;
// launch app when display is turned on and inside region
region.notifyEntryStateOnDisplay = YES;
if ([CLLocationManager isMonitoringAvailableForClass:[CLBeaconRegion class]])
{
[_locationManager startMonitoringForRegion:region];
[_locationManager startRangingBeaconsInRegion:region];
}
//Region 2
CLBeaconRegion *region2 = [[CLBeaconRegion alloc] initWithProximityUUID:uuid2 major:major2 minor:minor2 identifier:identifier2];
region2.notifyOnEntry = YES;
region2.notifyOnExit = YES;
// launch app when display is turned on and inside region
region2.notifyEntryStateOnDisplay = YES;
if ([CLLocationManager isMonitoringAvailableForClass:[CLBeaconRegion class]])
{
[_locationManager startMonitoringForRegion:region2];
[_locationManager startRangingBeaconsInRegion:region2];
}
// and so on
After that in every self.locationManager delegate method make sure which beacon you have, for example:
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region {
if ([region isKindOfClass:[CLBeaconRegion class]]) {
CLBeaconRegion *beaconRegion = (CLBeaconRegion *)region;
// Find out which beacon you have,
// I check just UUID but maybe your beacons have the same uuid but major, minor are difference so you need to check minor/major as well
if ([beaconRegion.proximityUUID isEqual:UUIDFIRST]) {
//Do some stuff
}
}
}
If you want to see which beacon are nearest you use:
-(void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region
enumerate beacons array:
if ([region isKindOfClass:[CLBeaconRegion class]]) {
for (CLBeacon *beacon in beacons) { // 1
// do the checking which beacon you have
if ([beaconRegion.proximityUUID isEqual:UUIDFIRST]) { // 2
}
// check beacon.accuracy property this should gives you distance in meters meters
//beacon.accuracy // 3
}
}
}
// Extended
If you are in range two (or more) beacons the beacons are passed to you in beacons array. By calling [beacons lastObject] you get just one beacon. What you have to do is enumerate (go throughout all of the objects in array) see no 1 in my code above (I edited it a bit) and see what beacon you have (2) after that you compare the distance (3) and the one with less value is the nearest one.