Centurion
Centurion

Reputation: 14314

How properly to handle monitored hundreds of regions?

I need to monitor ~400 regions worldwide (some places in capitals with 1-3 km radius). However, there's a limit of monitored regions per app, so I cannot register them all at start. There's no concrete max number of regions in Apple docs, but some say that the safe max number of regions is 10 regions (here).

Apple docs state "To work around these limits, you should consider registering only those regions in the user’s immediate vicinity. As the user’s location changes, you can remove regions that are now farther way and add regions coming up on the user’s path". So, the questions is how and when to manage those regions?

The main callbacks are didEnterRegion and didExitRegion when using region monitoring. So at start, I though that everytime a user would enter some region, I would receive a notification where I could remove old regions, find relevant closest 10 regions and register them. But the problem will occur in cases when a user will not enter the closest region but will move more far away from them (for example fly with airplane from some place to the opposite place of the planet), and I will never get a change to update the list of monitored regions because didEnterRegion will never be called.

To work around this problem I'm thinking to add monitoring of significant changes because I should get callbacks (notifications) everytime one of the triangular cell towers change. So I could use those notifications to update a list of monitored regions quite frequently. That's it, what are your opinions on that?

Upvotes: 1

Views: 1053

Answers (1)

ipmcc
ipmcc

Reputation: 29946

The first thought that comes to mind is that if you have ten regions to work with, what you really want to do is set notifications on the 9 closest regions of interest and then one region that's not an actual region, but a meta-region around the current location. That way, you're more likely to receive a didExitRegion callback when the user moves away from the current location. At that point you deregister all 10 regions and repeat the process. (i.e. re-register 9 + meta region based on the new current location.)

As you propose, it also probably makes sense to get as many cracks at updating your ten regions as possible, so sure, adding a significant changes notification seems like a decent approach.

Another option, although probably frowned-upon, would be to tell the OS that your app is a VOIP application. This allows you to register for periodic wakeups. You could use these to update your regions. I don't know to what degree Apple audits the use of this facility, but it's something to try.

Upvotes: 3

Related Questions