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.
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];
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];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With