2

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?

Mihai Popa
  • 892
  • 1
  • 8
  • 25

2 Answers2

7

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.

Community
  • 1
  • 1
James Frost
  • 6,960
  • 1
  • 33
  • 42
  • Is there a way to get beacon information using only the regions info (basically, to get beacon information in the background)? – Mihai Popa Jan 21 '14 at 15:44
  • It seems as though you can call `startRangingBeaconsInRegion:` when `didEnterRegion:` has been called, but the app will only be awake for a very short amount of time. It's not really recommended to try and do this in the background. – James Frost Jan 21 '14 at 16:33
1

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.

CW0007007
  • 5,681
  • 4
  • 26
  • 31
  • I want to handle the ranging in the background.When the user enters in the range of a beacon I want to get detailed information about the beacon(s) - and this happens in this method. I am not interested about the proximity information so this is why I don't want this method to be called so much. I have also read that ranging requires more power than region monitoring and this could drain the user battery. – Mihai Popa Jan 21 '14 at 15:01