CLLocationManager startMonitoringForRegion limitations - ios

In the Apple documentation for startMonitoringForRegion method there is this text:
An app can register up to 20 regions at a time. In order to report region changes in a timely manner, the region monitoring service requires network connectivity.
Do this 20 regions are only for this app or globally?

It's 20 regions per app. I don't know if there's a top number globally (i.e. for the device).

Related

Do geofences (CLCircularRegion) and iBeacons (CLBeaconRegion) share the 20 limit?

Apple's shared documentation on monitoring geofences and iBeacon regions state within the geofencing section that there is a limit of 20 monitored regions for a single app:
For this reason, Core Location limits to 20 the number of regions that may be simultaneously monitored by a single app.
https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/LocationAwarenessPG/RegionMonitoring/RegionMonitoring.html
What is unclear is if this limit is for geofences and beacon regions combined, or if each type will have a limit of 20.
Are the 20 regions a shared limit? Or can I register 20 of each?
Both CLCircularRegion and CLBeaconRegion share the same pool of 20 maximum regions that CoreLocation allows to be monitored by the single app at the same time.
This restriction predates the introduction of CLBeaconRegion in iOS 7. When Apple built beacons into the same monitoring framework, CLBeaconRegion inherited the same restriction. If you monitor 20 CLCircularRegions, then try to start monitoring a CLBeaconRegion, you will get an error.
You can only specify a maximum number of 20 unique region Ids. But you don't need to specify the major and minor value of each of those. You can have same Id for your beacons/regions and change the major and minor values to overcome this limitation.

Unique notification for each Beacon (more than 20 beacons)

I'm building an iOS App, in which I would wish to handle more than 20 iBeacons. Basically all beacons added to the web portal have to be handled by the App. Since there is an iOS restriction to number of region to be monitored as 20, I'm unable to give different local notifications for beacons in same region (having same UUID).
Is there any way to handle this?
A few points:
The 20 region limit applies to the number of CLRegion objects that can be registered by a single app. It does not mean you can only detect 20 beacons. Since each CLRegion object can leave the major and/or minor nil (making the fields a wildcard), each one can match billions of beacons.
Beacon apps typically use local notifications, not push notifications.
The way you set up many different notifications to come from many different beacons is like this:
Define a single wildcard region that matches all of your beacons. (Or a few regions if needed for background triggering).
Start monitoring and ranging for each of these regions.
In the didRangeBeacond:inRegion callback keep a flag for each individual beacon to see if you have sent a notification for it before. If not, set the flag to true and trigger a local notification specific to that beacon's identifiers.

Is it possible to just register and collect matching UUIDs with an iphone in the background without the phone waking up?

I just want the phone the register matching UUIDs and collect those in the background with core bluetooth and when I wake up the phone and enter an dedicated app to see which UUIDs the phone registered. Is that even possible?
Also I read about there being a register limit of only 20 beacons. Is there a way to extend that limit?
Edit: The phone is also advertising
Yes, you can monitor beacon regions in the background. This is using the Core Location framework though, not the Core Bluetooth framework. When a matching region is entered or exited you will receive a delegate callback if you have been granted "always" location permission. You only have a few seconds to execute in the delegate method or a couple of minutes if you launch a long running task.
There is a limit of 20 simultaneous region registrations, however ideally all of your beacons will have the same UUID so they can be handled with a single region.

Time spend around a beacon

What should be the correct approach to identify time spend around a beacon[not within a region] in background. I am able to do this when app is in foreground using didRangeBeacons and some business logic.I read on few forums that ranging does work when app has registered for location updates in background, but i am having no success. I have added the location updates key for UIBackgroundModes in plist.
I am using estimote beacons and their sdk.
I see two possible solutions here:
Listen for enter and exit region events, store the timestamps and then use them to calculate the time span on exit. If you define your region so that it encompasses only one beacon, monitoring the region will be equivalent to monitoring the beacon. The only thing to keep in mind is that iOS imposes a limit of 20 regions to be monitored at the same time - so this solution doesn't scale above 20 beacons.
Use ranging in the background. Apart from the UIBackgroundModes, you also need to start regular location services, i.e. startUpdatingLocation.
Beacon ranging delivers events normally while an app is running in the foreground. When your app is in the background, this service delivers events only when the location-updates background mode is enabled for the app and the standard location service is running.
(this is from CLLocationManager class reference, section "Using Location Services in the Background")
Note that ranging in the background will be draining the battery life more than usual, and Apple also requires justification for using the background modes. Unless there's some value for the user of your app coming from the background modes, they might choose to reject it. All in all, use the background ranging wisely! (:

iOS : Region monitoring and battery usage

I would like to use region monitoring in iOS , for location based alerts/calculations.
I'm worried that it would drain the battery.
I searched for it on the iOS reference , and couldn't find any evidence for it.
Is that service available at all times , regardless of the region monitoring (i.e. scanned every minute or so...) or should I use the "significant location change" API instead ?
update : so , battery usage isn't dramatic. Its pretty good actually.
would like to receive some advice regarding switching between the modes (region/standard).
After checking for almost 2 weeks , I can tell that region monitoring does not significantly drain the battery.
As a matter of fact , it will be an active service in iOS 5 for sure , as the built-in reminders app will use region monitoring 24/7.
Region monitoring shouldn't have anywhere near the same affect on battery life as location tracking does.
According to Apple's developer documentation, region monitoring is built upon CoreLocation's "significant-change" location service. In order to conserve battery life, this service does not poll position information using aGPS, but instead simply tracks changes in the user's current cell tower.
Whenever the cell tower changes, iOS calculates whether any region boundaries were crossed. If a region crossing occurs while an iOS app is not running, iOS automatically wakes it up (or relaunches it) in the background so that it can process the event via the didEnterRegion:/didExitRegion: callbacks.

Resources