Number of “region” monitored by RegionMonitoring, based on users current location in iOS7

后端 未结 1 1049
情书的邮戳
情书的邮戳 2020-12-16 06:22

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
相关标签:
1条回答
  • 2020-12-16 07:17

    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];
    
    0 讨论(0)
提交回复
热议问题