5

I am working on such a project where apps do the following things:

  1. User select a radius (10 meter to 1000 meter) and go to next viewController by pressing "Go" button
  2. Here apps Grab users current position and start "region monitoring" based on that current position with selected radius
  3. If the user cross that certain boundary (10 meter to 1000 meter) then it gives an "ExitRegion" alert message. And start "region monitoring" again based on users new current position. And the apps keep doing this all the time, both foreground and background mode. I manage to do it & it is working perfectly.

Now, Here I monitor one region, after that another one. So the number is actually one. But I know the maximum number of regions one apps can monitored by "Region Monitoring" is 15. Now my question is in this case should I handle this maximum number of region issue or not? If yes, then how?

One more thing I want to add is, there are some solution of it, which is only work for iOS 6 and earlier. So please let me know if there have some solution of handling number of "region" monitored by "RegionMonitoring", based on users current location in iOS7.

It will be a great pleasure to me if one can give the answer or any suggestion to finish my apps required requirements.

Donald Duck
  • 8,409
  • 22
  • 75
  • 99
Tulon
  • 4,011
  • 6
  • 36
  • 56

1 Answers1

7

If you check the docs, max limit is 20. When you exceed this number, the iOS will release monitoring of the oldest region (think its like its a FIFO queue). Make sure you keep the radius smaller than maximumRegionMonitoringDistance. So in other words you don't need to worry about max limit, you can make sure this by implementing didStartMonitoringForRegion: delegate.

But, If you want to control number of regions being monitored by yourself, you can always stop monitoring a region using stopMonitoringForRegion: You can get a list of regions being monitored with the property monitoredRegions. You can always clear up the region you don't need any more. It's a good practice to keep it minimum as it does effect the battery and app performance.

I'm using following code to clear up all my regions when required.

for (CLCircularRegion *region in self.locationManager.monitoredRegions) {
    [self.locationManager stopMonitoringForRegion:region];
}

But in your case, I would suggest using a constant for Region identifier (e.g. "MY-REGION"), as you cannot monitor two regions with same identifier, adding an other region with the same id removes previously monitored region automatically.

CLCircularRegion *region = [[CLCircularRegion alloc] initWithCenter:coordinate radius:50.0f identifier:@"MY-REGION"];
[self.locationManager startMonitoringForRegion:region];
quant24
  • 393
  • 6
  • 22
Zee
  • 1,865
  • 21
  • 42
  • Thanks for giving the suggestion. I want to delete previous monitored region in every step. What i mean is, when user exit a region then it delete previous region & start another "region monitoring" based on users current position. I try with this : `[locationManager stopMonitoringForRegion:[[[locationManager monitoredRegions] allObjects] objectAtIndex:0]];` and called it just at the beginning of the starting monitoring region. But not working properly. Do you have any idea about that? -Thanks – Tulon Feb 25 '14 at 07:31
  • I've done some testing on an iOS8 iphone 5s. Once you hit 20 regions, you will no longer set any more. Old regions don't get evicted. Also, if anyone is curious (because the documentation isn't clear on this) you get to set 20 BeaconRegions and 20 CircularRegions. – James Sep 04 '15 at 18:04