difference between didEnterRegion and didRangeBeacons

落花浮王杯 提交于 2019-12-10 17:39:29

问题


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

回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/26251076/difference-between-didenterregion-and-didrangebeacons

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!