Search code examples
iosibeaconregions

Does iOS indicate if a region is deactivated?


I am researching iOS beacon apps and have come across a concerning spec. From my understanding there is a maximum of 20 regions that can be enabled/defined at one time in iOS 8+ (total - not per app). A few of questions that come up after reading that.

  1. Are beacon regions different than GPS/geofencing regions, or are they all considered the same? Do they all count towards the 20 region max?
  2. If a device has more than 20 regions defined across different apps, how does one know if their region is actively being monitored?
  3. If a region is deactivated/replaced by a different region from a competing app, is there a notification sent to the app prior to the region being deactivated?
  4. How to reactivate a region once it has been pushed out by another app?

From what I have read, there is no "priority" levels when it comes to regions, and nothing to indicate which regions should be active. Does it work based on which apps were accessed/brought to foreground most recently?


Solution

  • The italicized parts of the answers below are direct quotes from Apple's docs, with links to the relevant page.

    Are beacon regions different than GPS/geofencing regions, or are they all considered the same? Do they all count towards the 20 region max?

    The region monitoring service operates independently of any location services in use by your app, and you may use it in conjunction with any of the other services. From "CLLocationManager Class Reference."

    If a device has more than 20 regions defined across different apps, how does one know if their region is actively being monitored?

    Be judicious when specifying the set of regions to monitor. Regions are a shared system resource, and the total number of regions available systemwide is limited. For this reason, Core Location limits to 20 the number of regions that may be simultaneously monitored by a single app. To work around this limit, consider registering only those regions in the user’s immediate vicinity.... (emphasis added) See "Region Monitoring and iBeacon" in Location and Maps Programming Guide for more.

    Since you're limited to 20 regions per app, it stands to reason that the system is actually capable of monitoring more than that. Considering the advice above, it seems unlikely that you should ever need to monitor anywhere close to 20 regions all at the same time.

    If a region is deactivated/replaced by a different region from a competing app, is there a notification sent to the app prior to the region being deactivated?

    If you attempt to register a region and space is unavailable, the location manager calls the locationManager:monitoringDidFailForRegion:withError: method of its delegate with the kCLErrorRegionMonitoringFailure error code. See "Region Monitoring and iBeacon" in Location and Maps Programming Guide for more.

    Sounds like regions aren't deactivated until you remove them, but you may not be able to add regions if there's no space. In that case you get an error as explained in the quote.

    How to reactivate a region once it has been pushed out by another app?

    See above. It's not a first-in-first-out arrangement, but more like musical chairs. If there's no space, you don't get to add your region in the first place.