difference between didEnterRegion and didRangeBeac

2019-06-28 02:23发布

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
{
}

2条回答
趁早两清
2楼-- · 2019-06-28 03:02

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 then didEnterRegion 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 once didExitRegion is called.

See also - The Location Programming Guide

查看更多
ゆ 、 Hurt°
3楼-- · 2019-06-28 03:26

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 the CLBeaconRegion, 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:

  1. To get details of the nearby beacons that correspond to a partially qualified region.

This information is provided to didRangeBeacons as an array of CLBeacon objects. Note that the set of beacons can change over time without the device leaving the region and receiving a didExitRegion (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 of didRangeBeacons.

  1. To get the proximity information provided in the 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.

查看更多
登录 后发表回答