Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

diddeterminestate not always called

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.

like image 625
Allen Avatar asked Jul 03 '14 01:07

Allen


2 Answers

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];
like image 186
Jeff Ames Avatar answered Nov 03 '22 22:11

Jeff Ames


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];
}
like image 42
EPage_Ed Avatar answered Nov 03 '22 22:11

EPage_Ed