I want to do the following:
If a user remains still in a CLBeaconRegion
for an extended period of time (roughly 15 minutes), I want to be able to execute some piece of code. This problem is trivial if the app is in the foreground, but I'm having trouble extending the background time to the allotted time. Because I am using location services, it should be permissible to have such a long background task running.
Both didEnterRegion
and didExitRegion
are called in the background only when the user moves. There does not appear to be any location-specific API that allows you to do background tasks in respect to time.
There does appear to other similar questions that want to achieve the same thing, such as all the threads mentioned here. However, it doesn't seem that the proposed solutions would work for a CLBeaconManager
(which essentially involves disabling and enabling CLLocationManager
when the backgroundTimeRemaining
is sufficiently small, but my initial attempts with this solution didn't work out)
Another way I can do this with a limited scope is to schedule a notification in 15 minutes, and cancel the notification in didExitRegion
.
However, the solutions above feel either hacky or inadequate. Is there an "elegant" way to accomplish what I want?