Search code examples
iosobjective-cxcodeibeaconestimote

didRangeBeacons returns only one iBeacons at a time


I am trying to detect the multiple iBeacons. i have placed a three iBeacons near by them.

Problem its detecting one by one. Not in a array. it should return 3 iBeacons.

self.beaconManager = [[ESTBeaconManager alloc] init];
self.beaconManager.delegate = self;

self.region1 = [[ESTBeaconRegion alloc] initWithProximityUUID:ESTIMOTE_PROXIMITY_UUID major:21668 minor:53482 identifier:@"EstimoteSampleRegion"];

self.region2= [[ESTBeaconRegion alloc] initWithProximityUUID:ESTIMOTE_MACBEACON_PROXIMITY_UUID major:3894 minor:57726 identifier:@"EstimoteSampleRegion2"];

self.region3= [[ESTBeaconRegion alloc] initWithProximityUUID:ESTIMOTE_IOSBEACON_PROXIMITY_UUID major:13067 minor:31901 identifier:@"EstimoteSampleRegion3"];


[self.beaconManager startRangingBeaconsInRegion:_region1];
[self.beaconManager startRangingBeaconsInRegion:_region3];
[self.beaconManager startRangingBeaconsInRegion:_region2];

// Delegate methods

 -(void)beaconManager:(ESTBeaconManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(ESTBeaconRegion *)region {
        //checks bRegion, so you could have it searching for other beacons if you wanted after one is notified

        NSLog(@"Start");
        for (ESTBeacon *iBeacon in beacons) {
            NSLog(@"%@",iBeacon.minor);
        }
        NSLog(@"Finish");


    }

Console O/p

Start
57726
Finish

Start
53482
Finish

Start
31901
Finish

Start
57726
Finish

Solution

  • If you look at the method signature you will see it is -

     didRangeBeacons:inRegion:
    

    Note the 'inRegion' - Your three beacons are in separate regions, so you are getting individual calls for each region.

    If you change your region initialisation to -

    self.region1 = [[ESTBeaconRegion alloc] initWithProximityUUID:ESTIMOTE_PROXIMITY_UUID identifier:@"EstimoteSampleRegion"];
    

    and delete the other two regions, then you will receive notification for all three beacons in the same region. You will need to examine each major and minor individually to determine which is which.

    If you give all of the beacons the same major then you can specific the major in your region and you will only be notified for "your" beacons, not all Estimote beacons (unless someone else chooses the same major that is...)