Yes, you can stop monitoring CLBeaconRegion
s depending on the user's location. But as you've discovered, the center
property of this object won't help you do that (See @Daij-Djan's answer for an explanation as to why.)
The typical way to do you want is to set up to receive significant location changes using CLLocationManager
at the same time as you set up beacon monitoring, like this:
[locationManager startMonitoringSignificantLocationChanges];
You then add a method like below to the delegate
of your CLLocationManager
to get callbacks each time the user changes locations significantly:
- (void)locationManager:(CLLocationManager *)locationManager
didUpdateLocations:(NSArray *)locations {
CLLocation* location = [locations lastObject];
NSLog(@"latitude %+.6f, longitude %+.6f\n",
location.coordinate.latitude,
location.coordinate.longitude);
// TODO: change the monitored beacon regions depending on the
// location.coordinate.latitude and location.coordinate.longitude
}
}
Note that you also need to make sure location services are authorized for your app for this to work and put a string corresponding to the NSLocationAlwaysUsageDescription
key in your plist, but it is the same check you need to do to monitor for beacons anyway:
if([locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
[locationManager requestAlwaysAuthorization];
}
See here for more details on signficant location changes: https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/LocationAwarenessPG/CoreLocation/CoreLocation.html