Question

On iOS, in my application delegate I start region monitoring and as soon as I enter in a beacon region I start the ranging logic, using locationManager:didRangeBeacons:inRegion. According to the Apple documentation, this method should be called only when the the region comes within the range or out of the range or when the range changes.

My problem is that I get a call to this method every second as long as I am inside the region. How to decrease the number of calls to this method while still ranging?

Was it helpful?

Solution 2

According to the Docs:

"The location manager calls this method whenever a beacon comes within range or goes out of range. The location manager also calls this method when the range of the beacon changes; for example, when the beacon gets closer."

Whats probably happening is the range is changing slightly which is causing the behaviour you describe.

Why is this a problem

EDIT:

IN the background you will get notified of entering regions via the app delegate method:

- (void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region{}

You can use this to determine the state:

if(state == CLRegionStateInside)
{
    //Inside a region:
}
else if(state == CLRegionStateOutside)
{
    //Outside a region
}
else {
    //Something else
}

You can use this to gather a limited amount of information or prompt the user to load the application via a local notification. When your app resumes you can then gather more information via the locationManager.

OTHER TIPS

locationManager:didRangeBeacons:inRegion is called once per second, no matter what. Each time it's called, the beacons parameter will contain an array of all beacons that the app can currently see, ordered by proximity. There's no way to limit the frequency at which this method is called, short of stopping ranging.

When monitoring regions (instead of ranging), your app will have didEnterRegion: and didExitRegion called, along with didDetermineState:. See this answer for a little more detail.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top