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:
The location manager calls this method whenever there is a boundary transition for a region. It calls this method in addition to calling the
locationManager:didEnterRegion:
andlocationManager:didExitRegion:
methods. The location manager also calls this method in response to a call to itsrequestStateForRegion:
method, which runs asynchronously.
So didDetermineState
should get called whenever didEnterRegion
/didExitRegion
do. In addition, if you explicitly request the state via requestStateForRegion
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
When set to YES, the location manager sends beacon notifications when the user turns on the display and the device is already inside the region. These notifications are sent even if your app is not running. In that situation, the system launches your app into the background so that it can handle the notifications. In both situations, the location manager calls the
locationManager:didDetermineState:forRegion:
method of its delegate object.
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