Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CoreLocation kCLErrorDomain error 5

I subclassed a CLRegion to support Polygons via overriding containsCoordinate: to use ray casting logic instead of the original distance crunching logic. The subclass is initialized via the normal method (initCircularRegionWithCenter:radius:identifier:), then CLLocationCoordinate2ds are added as NSValues to a mutable array. These coordinates are used during the ray casting logic.

As soon as I try to use the CLRegion subclass, I am confronted with a ton of errors in my application logic, as well as the following error:

2013-07-18 16:46:44.515 Geofencing[4816:907] (identifier 6C11CBAF-3EE4-4257-9D75-9724F4349B5D) <+39.86605072,-75.54420471> radius 186.54m: Error Domain=kCLErrorDomain Code=5 "The operation couldn’t be completed. (kCLErrorDomain error 5.)"

I also tried a different subclass that does not modify any methods but adds a method for reading metadata from an NSDictionary. I was confronted with the same error.

What is going on? Is subclassing CLRegion feasible?

like image 771
Nate Symer Avatar asked Jul 18 '13 21:07

Nate Symer


5 Answers

I hate to answer my own question, but I have found the solution to my issue. A kCLErrorDomain code/error of 5 denotes that you have tried to monitor more than 20 CLRegions. In my case, both subclasses were guilty of monitoring more than 20 regions.

like image 115
Nate Symer Avatar answered Oct 31 '22 18:10

Nate Symer


Also: if you're testing with iBeacons, you can't use the iOS simulator.

like image 28
wspruijt Avatar answered Oct 31 '22 19:10

wspruijt


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];
    }
}
like image 34
user3648465 Avatar answered Oct 31 '22 19:10

user3648465


It is also possible to get this error code back when your latitude and longitude values don't make sense. (I'd transposed them, for example, and was vexed by this error for a while.)

like image 38
Sean McMains Avatar answered Oct 31 '22 19:10

Sean McMains


This error could also rise up if added CLRegion is nil.

like image 2
Shmidt Avatar answered Oct 31 '22 18:10

Shmidt