Monitoring multiple beacons in side for loop not working

Hi,
I have to monitor only 20 estimote beacons when app in background .The major and minor values of beacons which are to monitored will come from server.

i am writing code like this

for (int beaconCount=0; beaconCount <[BeaconArray count]; beaconCount++)
{

                 //Start Monitoring beacons
            CLBeaconMajorValue major = [[[BeaconArray objectAtIndex:beaconCount] objectForKey:@"major"] integerValue];
            CLBeaconMinorValue minor = [[[BeaconArray objectAtIndex:beaconCount] objectForKey:@"minor"] integerValue];

            NSUUID *serverUUID = [[NSUUID alloc] initWithUUIDString:[[BeaconArray objectAtIndex:beaconCount] objectForKey:@"uUID"]];

            NSString *strIdentifier = [NSString stringWithFormat:@"EstimoteRegion%d",beaconCount];

// ESTBeaconRegion *beaconRegion = [[ESTBeaconRegion alloc] initWithProximityUUID:ESTIMOTEPROXIMITYUUID major:major minor:minor identifier:strIdentifier];
ESTBeaconRegion *beaconRegion = [[ESTBeaconRegion alloc] initWithProximityUUID:ESTIMOTEPROXIMITYUUID major:major minor:minor identifier:strIdentifier];

            beaconRegion.notifyEntryStateOnDisplay = YES;
            beaconRegion.notifyOnEntry=YES;
            beaconRegion.notifyOnExit=YES;

            ESTBeaconManager *beaconManager = [[ESTBeaconManager alloc] init];
            beaconManager.delegate = self;
            [beaconManager startMonitoringForRegion:beaconRegion];

        }

The beacons are not getting monitored with this code.But if i try

int major1 = 3597;
int minor1 = 4483;

self.beaconRegion1 = [[ESTBeaconRegion alloc] initWithProximityUUID:ESTIMOTE_PROXIMITY_UUID major:major1 minor:minor1 identifier:@"Skyblue"];
self.beaconRegion1.notifyEntryStateOnDisplay = YES;
self.beaconRegion1.notifyOnEntry=YES;
self.beaconRegion1.notifyOnExit=YES;

self.beaconManager1 = [[ESTBeaconManager alloc] init];
self.beaconManager1.delegate = self;
[self.beaconManager1 startMonitoringForRegion:self.beaconRegion1];


int major2 = 48239;
int minor2 = 41497;

self.beaconRegion2 = [[ESTBeaconRegion alloc] initWithProximityUUID:ESTIMOTE_PROXIMITY_UUID major:major2 minor:minor2 identifier:@"Lightgreen"];
self.beaconRegion2.notifyEntryStateOnDisplay = YES;
self.beaconRegion2.notifyOnEntry=YES;
self.beaconRegion2.notifyOnExit=YES;

self.beaconManager2 = [[ESTBeaconManager alloc] init];
self.beaconManager2.delegate = self;
[self.beaconManager2 startMonitoringForRegion:self.beaconRegion2];



int major3 = 18112;
int minor3 = 50393;

self.beaconRegion3 = [[ESTBeaconRegion alloc] initWithProximityUUID:ESTIMOTE_PROXIMITY_UUID major:major3 minor:minor3 identifier:@"Violet"];
self.beaconRegion3.notifyEntryStateOnDisplay = YES;
self.beaconRegion3.notifyOnEntry=YES;
self.beaconRegion3.notifyOnExit=YES;

self.beaconManager3 = [[ESTBeaconManager alloc] init];
self.beaconManager3.delegate = self;
[self.beaconManager3 startMonitoringForRegion:self.beaconRegion3];

Like this the beacons are getting detected.Can any one tell me whats wrong with for loop code.

Unfortunately I have the same problem and could not solve it so far. A short response from the Estimote-Team would be appreciated.

In the 1st piece of code:

ESTBeaconManager *beaconManager = [[ESTBeaconManager alloc] init];
beaconManager.delegate = self;
[beaconManager startMonitoringForRegion:beaconRegion];

You create a local instance of ESTBeaconManager, that'll get automatically destroyed by iOS memory management mechanism at the end of the loop. That's why monitoring doesn't work.

In the 2nd piece of code:

self.beaconManager1 = [[ESTBeaconManager alloc] init];

You assign the ESTBeaconManager to a class property, which prevents it from getting destroyed as long as the instance of the class exists. Hence it works.

FYI, you can monitor multiple regions with just one beacon manager, and unless you have a really good reason to create more of them, it's usually a good idea so stick to a single one, as it conserves memory.