Diddeterminestate is not always called

Does anyone else have a problem that diddeterminestate is not always called? Sometimes i call

[self.locationManager requestStateForRegion:region]; 

and nothing happens. Curiously, when I insert a breakpoint in

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

It starts to work and is called! It seems very unstable to me.

+6
source share
2 answers

I often encountered this problem when querying the state of a region immediately after it was monitored.

eg.

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

I guaranteed that didDetermineStateForRegion was invoked by scheduling requestStateForRegion: shortly after calling startMonitoringForRegion. Now this is not a great solution and should be used carefully, but it seems to be a daunting problem for me. Code below

 [self.locationManager startMonitoringForRegion:region]; [self.locationManager performSelector:@selector(requestStateForRegion:) withObject:region afterDelay:1]; 
+11
source

Perhaps calling callStateForRegion inside the delegation method didStartMonitoringForRegion would be better. It is likely that requestStateForRegion is started before monitoring (asynchronous) has begun.

 - (void) locationManager:(CLLocationManager *)manager didStartMonitoringForRegion:(CLRegion *)region { NSLog(@"Started Monitoring for Region:\n%@",region.description); [self.locationManager requestStateForRegion:region]; } 
+2
source

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


All Articles