Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iBeacon : What is the difference between didEnterRegion and didDetermineState(CLRegionStateInside)

Tags:

ios

ibeacon

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;
    }
} 
like image 632
zono Avatar asked Jan 19 '14 07:01

zono


1 Answers

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: and locationManager:didExitRegion: methods. The location manager also calls this method in response to a call to its requestStateForRegion: 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.

like image 62
James Frost Avatar answered Nov 08 '22 14:11

James Frost