While testing with beacons (iOS devices) I found the listener beacon giving some unexpected behavior. locationManager:didEnterRegion method is not getting called even if a beacon enters a region. But the locationManager:didRangeBeacons:inRegion: is getting called correctly, and detected beacons are shown there. Has anyone experienced anything like this.
Check if your methods are implemented in the following way.
In viewDidLoad
, start moniotoring at the end
self.beaconRegion.notifyOnEntry=YES;
self.beaconRegion.notifyOnExit=YES;
self.beaconRegion.notifyEntryStateOnDisplay=YES;
[self.locationManager startMonitoringForRegion:self.beaconRegion];
after monitoring start, request state for your defined region
- (void) locationManager:(CLLocationManager *)manager didStartMonitoringForRegion:(CLRegion *)region
{
[self.locationManager requestStateForRegion:self.beaconRegion];
}
after state is determined, start ranging beacons
-(void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region
{
if (state == CLRegionStateInside)
{
//Start Ranging
[manager startRangingBeaconsInRegion:self.beaconRegion];
}
else
{
//Stop Ranging here
}
}
and implement the following methods according to your needs...
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region
{
self.statusLbl.text=@"Entered region";
}
-(void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region
{
self.statusLbl.text=@"Exited region";
}
-(void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region
{
if(beacons.count>0)
{}
}
Hope this will solve your problem.