CoreLocation kCLErrorDomain error 5

I subclassed a CLRegion to support polygons by overriding containsCoordinate: to use the ray casting logic instead of the original crystal distance logic. The subclass is initialized using the usual method ( initCircularRegionWithCenter:radius:identifier: , then CLLocationCoordinate2d added as an NSValue to the mutable array. These coordinates are used during the beam swing logic.

As soon as I try to use the CLRegion subclass, I encounter many errors in my application logic, as well as an 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 another subclass that does not modify any methods, but adds a method for reading metadata from NSDictionary. I came across the same error.

What's happening? Is it possible to subclass CLRegion?

+6
source share
5 answers

I hate answering my question, but I found a solution to my problem. a kCLErrorDomain code / error 5 means you tried to control more than 20 CLRegions . In my case, both subclasses were guilty of monitoring more than 20 regions.

+17
source

This also happens if you:

stop monitoring the area

 [self.manager stopMonitoringForRegion:region]; 

and immediately request a status for all controlled regions:

 for (CLRegion *region in self.manager.monitoredRegions) { [self.manager requestStateForRegion:region]; } 

you get kCLErrorDomain 5 because IOS seems to have disabled monitoring for this region but not removed it from the monitoredRegions array yet

 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 this issue, follow these steps:

 - (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]; } } 
+8
source

Also: if you are testing iBeons, you cannot use the iOS simulator.

+5
source

You can also return this error code when your latitude and longitude values ​​do not make sense. (I transferred them, for example, and for a while I was unhappy with this error.)

+3
source

This error can also increase if CLRegion nil added.

+2
source

Source: https://habr.com/ru/post/949782/


All Articles