I want to post a notification when users enter into a region. However, I am very confused because of same two CLLocationManagerDelegate methods. How should I use the two methods properly?
Some people say "didDetermineState" method is needed to start region observation if the app start in the region.
Thanks,
- (void)locationManager:(CLLocationManager *)manager
didEnterRegion:(CLRegion *)region
{
[self sendNotification:@"didEnterRegion"];
}
- (void)locationManager:(CLLocationManager *)manager
didDetermineState:(CLRegionState)state
forRegion:(CLRegion *)region
{
switch (state) {
case CLRegionStateInside:
[self sendNotification:@"didEnterRegion"];
break;
case CLRegionStateOutside:
break;
case CLRegionStateUnknown:
break;
default:
break;
}
}
Apple's documentation for CLLocationManager states:
So
didDetermineState
should get called wheneverdidEnterRegion
/didExitRegion
do. In addition, if you explicitly request the state viarequestStateForRegion
it will be called.There's one other behaviour that triggers this method: if you're monitoring a region on which you've enabled the
notifyEntryStateOnDisplay
property, the method will be called whenever the user wakes their device manually, and they are within the region you are monitoring. From the documentation