MonitoredRegions is empty although startMonitoringForRegion: wishAccuracy: is called

I am developing an application for iPhone running on iOS5 and cannot configure startMonitoringForRegion:desiredAccuracy: when I call the startMonitoringForRegion:desiredAccuracy: method with the click of a button.

It works fine in the simulator when I print out areas in monitoredRegions , but when working on a real iPhone 4, monitoredRegions always empty. The didEnterRegion: and didExitRegion: also not didExitRegion: to be called.

Another mysterious fact is that on the BOTH simulator and iPhone 4 device, the CLLocationManagerDelegate didStartMonitoringForRegion: method is also not called.

Would thank for the help here, thanks!

EDIT: this is the method that I call with a button click:

 -(void) queueGeofence: (CLLocationCoordinate2D)selectedBranch userCoordinate:(CLLocationCoordinate2D)userCoordinate radius: (CLLocationDegrees)radius { geofence = [[CLRegion alloc] initCircularRegionWithCenter:selectedBranch radius:radius identifier:@"geofence"]; CLLocationAccuracy acc = kCLLocationAccuracyNearestTenMeters; [locationManager startMonitoringForRegion:geofence desiredAccuracy:acc]; [CLLocationManager regionMonitoringEnabled]; NSLog([CLLocationManager regionMonitoringEnabled] ? @"regionMonitoringEnabled:Yes" : @"regionMonitoringEnabled:No"); NSLog([CLLocationManager regionMonitoringAvailable] ? @"regionMonitoringAvailable:Yes" : @"regionMonitoringAvailable:No"); NSLog(@"LOCATIONMANAGER monitored regions: %@", [locationManager monitoredRegions]}); } 

Regional monitoring is enabled and available, but monitoredRegions still does not return anything.

+4
source share
3 answers

If you look in CLLocationManager.h, the comments in the header for startMonitoringForRegion:desiredAccuracy: indicate that

If a region with the same identifier is already being tracked for this application, it will be removed from monitoring. This is done asynchronously and cannot be immediately reflected in the controlled Regions.

Therefore, you do not have to expect that [locationManager monitoredRegions] will include your added area as it is added asynchronously.

Are you implementing the delegate method for locationManager:monitoringDidFailForRegion:withError: :? Perhaps this is a call instead of locationManager:didStartMonitoringForRegion: Also note that the area with the same identifier as the existing region will be deleted, so you may encounter some unexpected problems because you are reusing "geofence" as your identifier.

+3
source

First of all, you must be sure that your application has permission to use the LocationManager . Check this out when you appoint your manager.

 [CLLocationManager authorizationStatus]; 

I had the same problem when I started the application and refused permission. And after uninstalling and restoring the application. I had a flag, this user did not accept it. Turn it on.

+1
source

If you're just going to your NSLog, this probably won't work. [locationManager monitoringedRegions] returns NSSet CLRegions. They will not appear in your journal in this way. Try the following:

 NSSet *setOfRegions = [locationManager monitoredRegions]; for (CLRegion *region in setOfRegions) { NSLog (@"region info: %@", region); } 
+1
source

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


All Articles