4

I am afraid I know the answer to this.

Apple's location manager docs for the startMonitoringForRegion method say that you can monitor a maximum of 20 regions at a time.

I have a client app that makes heavy use of both geofence regions and beacon regions.

I had assumed that there were separate 20 region limits for geofence regions and beacon regions, but I fear that the limit is actually 20 regions total for both types.

Can somebody confirm my fears based on actual experience?

Duncan C
  • 128,072
  • 22
  • 173
  • 272

2 Answers2

5

Yes, the 20 region limit is the maximum that CoreLocation lets you monitor for both CLBeaconRegions and CLCircularRegions (geofences) combined. When iOS 7 added beacon support, beacon regions inherited this same limitation for geofences because of the ways the APIs were defined. And as you suspected, the limit applies to any type of region you want to monitor. So you can monitor 10 CLBeaconRegions and 10 CLCircularRegions but no more than 20 combined of each type.

davidgyoung
  • 63,876
  • 14
  • 121
  • 204
  • Sigh. I was afraid of that. Do you know why Apple imposes the 20 region limit? – Duncan C Mar 23 '16 at 18:18
  • I don't know why apple chose exactly 20 as a limit, but some limit seems reasonable. The more geofences an app has the more work the OS has to do each time location changes to see if one gets tripped. The difference between 20 and 40 may be small, but imagine an app that had 1000! For beacons, there are a limited the number of slots available on the bluetooth chip for hardware filtering for rapid beacon detection. There is evidence that on some iOS devices there is a system wide limit of 30 slots, meaning two apps will more than use up all these slots with 20 beacon regions each. – davidgyoung Mar 24 '16 at 02:13
  • @davidgyoung This hardware-limit of 30 applies only for detectable beacons at the same time. Imagine you are in a store and have 30 beacons in your near vicinity - that's about this limit. This is the hard(ware) limit. And there is no soft(ware) limit in fact. Think about it - _every_ Beacon is first recognised and _then_ the found ID is checked against the registered Beacons on the device. So on the device side there is just the indexed list of registered Beacon IDs which has to be searched thru. The same applies for Geofences. – Darko Jul 11 '17 at 11:44
  • Hi, I don't know if this has changed lately, but I believe the maximum is 15 and if you try to add another one, it will not automatically release the oldest but just fail in creating a new monitored region. – Holger Feb 05 '18 at 19:56
  • @Holger, yes, it is true that after you reach the limit you will get an error and no more can be added. However, I do not believe that the limit has been changed from 20. Check that you don't already have some set up when your application starts up by counting how many already exist on locationManager.monitoredRegions – davidgyoung Feb 06 '18 at 00:06
1

The limit is 20 for each type of CLRegion. This means you can monitor 20 CLCircularRegion and 20 CLBeaconRegion.

This isn't documented but I did some tests and added more than 20 CLBeaconRegion and more than 20 CLCircularRegion. The results were that self.locationManager.monitoredRegions.count was 40 having 20 monitoredRegions of type CLCircularRegion and the other 20 of type CLBeaconRegion.

Once you reach the limit for each type of CLRegion and you try to monitor new regions (of that type) they get ignored and locationManager:monitoringDidFailForRegion:withError: is called with the kCLErrorRegionMonitoringFailure error code.

Maikol
  • 11
  • 2
  • Your answer does not match my experience. After posting this question I tried it and found what David Young reported - that your app can only monitor a maximum of 20 regions total, not 20 of each type. If you try to add more than 20 some of them get ignored. – Duncan C Sep 13 '16 at 01:24
  • @DuncanC I tested this on iOS 9 and that was the result. Make sure that you are testing on a device since the simulator doesn't support monitoring `CLBeaconRegion` – Maikol Sep 13 '16 at 03:41
  • You don't get an error when you try to monitor more than 20 combined regions, but the regions in excess of 20 are ignored. In contrast you DO get an error if you try to add more than 20 regions of a single type. – Duncan C Jul 05 '17 at 11:12