I am monitoring both iBeacons and circular regions in iOS. If I try to define them separately:
- (void) locationManager:(CLLocationManager *)manager didExitRegion:(CLCircularRegion *)region {}
- (void) locationManager:(CLLocationManager *)manager didExitRegion:(CLBeaconRegion *)region {}
It is obviously a duplicate declaration error. This SO answer nicely indicates, how to differentiate which region fired. To get that far, I'm trying to figure out how to define a common region exit event, which everyone would be happy with. If I combine them using CLRegion
, there will be various warnings:
- (void) locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region
{
if (region.class == CLCircularRegion.class) {
CLLocationCoordinate2D coordinate = [region center]; // Deprecation warning, use CLCircularRegion instead
// etc...
}
if (region.class == CLBeaconRegion.class) {
[locationManager stopRangingBeaconsInRegion:region]; // Incompatible pointer types warning
// etc...
}
}
I originally defined beacon processing using didDetermineState
, but it results in some extra events. E.g. CLRegionStateOutside
fires initially for all monitored regions, which is entirely appropriate, but I don't need to know that, so I would rather be using didExitRegion
instead.
Is there a proper way to write a clean combined didExitRegion
so that it can process both circular and beacon regions without errors or warnings?