7

Does anyone else have a problem of having diddeterminestate not always being called? There are sometimes when I call

[self.locationManager requestStateForRegion:region]; 

and nothing happens. The curious thing is that when I insert a break point in

-(void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region

it starts working and being called! It seems very unstable to me.

Allen
  • 3,601
  • 10
  • 40
  • 59

2 Answers2

13

I often experienced this problem when requesting the state of a region right after monitoring it.

e.g.

[self.locationManager startMonitoringForRegion:region];
[self.locationManager requestStateForRegion:region];

I ensured that didDetermineStateForRegion was called by scheduling requestStateForRegion: shortly after calling startMonitoringForRegion. Now it's not a great solution and it should be used carefully but it seemed to fix this annoying issue for me. Code below

[self.locationManager startMonitoringForRegion:region];
[self.locationManager performSelector:@selector(requestStateForRegion:) withObject:region afterDelay:1];
Jeff Ames
  • 1,555
  • 11
  • 27
  • Aaahh. Seems like everybody is fighting the same windmills here...Encountered the same issue and this workaround - an ugly one, admitted - fixed it. – alexander.biskop May 11 '15 at 16:43
4

Perhaps putting the requestStateForRegion call inside the delegate method didStartMonitoringForRegion would be better. It's likely that the requestStateForRegion is being run before the monitoring (which is async) has actually started.

- (void) locationManager:(CLLocationManager *)manager didStartMonitoringForRegion:(CLRegion *)region {
    NSLog(@"Started Monitoring for Region:\n%@",region.description);
    [self.locationManager requestStateForRegion:region];
}
EPage_Ed
  • 1,173
  • 11
  • 11
  • whenever i call self.locationManager?.startMonitoring(for: currRegion) that time didStartMonitoringForRegion calling 2X. – imjaydeep Sep 13 '17 at 10:55