Reputation: 8049
While Testing with ibeacons in background mode, i have found a big problem with detection using:
IN FOREGROUND WORKS FINE
func locationManager(_ manager: CLLocationManager, didRangeBeacons beacons: [CLBeacon], in region: CLBeaconRegion) {}
The idea I want to implement is to manage on my own the time a beacon can be detected a second time, keeping me close to the beacon.
The problem is when try to detect the same beacon for second time (and sometimes even others for first time), for some strange reason this funcion is not called anymore, just after first detection.
The only way is remove battery from beacon (intermittent) or take my beacon and walk Until leaving the detection area (This always works).
for this last i'm using this function for verify:
func locationManager(_ manager: CLLocationManager, didDetermineState state: CLRegionState, for region: CLRegion) {
if (state == CLRegionState.inside)
{
print("didDetermineState inside!!!!")
}
else if (state == CLRegionState.outside)
{
print("didDetermineState outside!!!!")
}
else
{
print("didDetermineState Other!!!!")
}
}
Only executing some of this 2 option, the function is fired again
Thanks in advance.
Considering this answer, didRangeBeacons
should be executed constantly, but i'm experimenting didEnterRegion
issue.
I'm using both functions:
- didRangeBeacons: for beacons visibles in ranging.
- didEnterRegion: for Geofencing and beacons too
Upvotes: 0
Views: 642
Reputation: 64916
Beacon ranging on iOS generally only works when your app is in the foreground. Ranging in the background is limited to 10 seconds after your app goes into the background. If you are also monitoring (which it sounds like you are), it also gets an extra 10 seconds of background ranging time whenever there is an entry/exit event -- e.g. if all beacons in the CLBeaconRegion
stop being detected (exit) or after the first time one is detected (entry) after an exit event. This probably explains what you are seeing.
You can extend background ranging time up to 180 seconds by request, but you can only make it go on indefinitely with special background modes. I wrote a blog post that describes this in detail here.
Upvotes: 2