Backgroud ranging of Beacons

I am building an iOS - swift app to calculate time spent at each beacon location. i.e when the user enters a beacon range the timer starts, moving to another beacon’s range will stop the timer and save the data on cloudKit.
It is working fine when the app is in the foreground, But when the app is in background/ closed It only sends notifications, but the timer doesn’t start/stop when switching beacons. How can I achieve this in iOS-swift?

In the background, I’d suggest a different approach, since you can’t/shouldn’t do long-term ranging.

Instead, do monitoring, and in didEnter note down the timestamp of the event. Then, in didExit, take the timestamp, take current time, and calculate how long the user has been in range. And store that in iCloud.

1 Like

Thank you, It worked.

1 Like