What is the exact difference between didEnterRegion and didRangeBeacons in terms of use case i mean when i should implement didEnterRegion/didExitRegion and when should i implement didRangeBeacons ?
What are the each delegate method's exact functionality ? From apple's documentation it's not very clear.
- (void)locationManager:(CLLocationManager *)manager
didEnterRegion:(CLRegion *)region
{
}
AND
- (void)locationManager:(CLLocationManager *)manager
didRangeBeacons:(NSArray *)beacons
inRegion:(CLBeaconRegion *)region
{
}
didEnterRegion
will be called once when you cross the threshold of the region (i.e. detect the beacon). Once you exit the region (i.e. the beacon is no longer visible)didExitRegion
will be called and thendidEnterRegion
will be called again if you re-enter the region.didRangeBeacons
is called repeatedly while beacons that you are ranging are visible, giving you updated proximity information.A common strategy is to monitor for beacon regions and once
didEnterRegion
is called, start ranging that beacon for updates, stopping the ranging oncedidExitRegion
is called.See also - The Location Programming Guide
A
CLBeaconRegion
defined with just a proximity UUID, or a proximity UUID and Major id may correspond to multiple physical beacons in your deployment (I will call these 'partially qualified regions' here).didEnterRegion
notifies when the device first enters the proximity of one or more beacons that match theCLBeaconRegion
, but does not detail which matching beacons are nearby.didExitRegion
is only called when all matching beacons go out of range.There are two uses for ranging beacons once a region has been entered:
This information is provided to
didRangeBeacons
as an array ofCLBeacon
objects. Note that the set of beacons can change over time without the device leaving the region and receiving adidExitRegion
(as long as at least one matching beacon is within range, the device is in the region). This means that applications that use partially qualified regions but still care about the specific beacons need to process the repeated invocations ofdidRangeBeacons
.CLBeacon
objects.This may be relevant even if fully qualified regions are used. As proximity changes when the device moves within the region the repeated invocations of
didRangeBeacons
need to be processed.