I subclassed a CLRegion
to support Polygons via overriding containsCoordinate:
to use ray casting logic instead of the original distance crunching logi
It also happens if you:
stop monitoring a region
[self.manager stopMonitoringForRegion:region];
and request the state for all monitored regions shortly afterwards:
for (CLRegion *region in self.manager.monitoredRegions) {
[self.manager requestStateForRegion:region];
}
you will get the kCLErrorDomain 5 because IOS seems to have disabled the monitoring for that region, but has not yet removed it from the monitoredRegions array
monitoringDidFailForRegion CLCircularRegion (identifier:'Home', center:<...>, radius:102.00m) The operation couldn’t be completed. (kCLErrorDomain error 5.)
monitoredRegion: CLCircularRegion (identifier:'Home', center:<...>, radius:102.00m)
monitoredRegion: CLBeaconRegion (identifier:'BeaconHome', uuid:<..., major:(null), minor:(null))
monitoredRegion: CLCircularRegion (identifier:'D...', center:<...>, radius:101.00m)
monitoredRegion: CLCircularRegion (identifier:'W...', center:<..>, radius:51.00m)
to work around that problem, do something like this:
- (void)locationManager:(CLLocationManager *)manager monitoringDidFailForRegion:(CLRegion *)region withError:(NSError *)error
{
NSLog(@"monitoringDidFailForRegion %@ %@",region, error.localizedDescription);
for (CLRegion *monitoredRegion in manager.monitoredRegions) {
NSLog(@"monitoredRegion: %@", monitoredRegion);
}
if ((error.domain != kCLErrorDomain || error.code != 5) &&
[manager.monitoredRegions containsObject:region]) {
NSString *message = [NSString stringWithFormat:@"%@ %@",
region, error.localizedDescription];
[AlertView alert:@"monitoringDidFailForRegion" message:message];
}
}