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

标签 ios ibeacon

我想在用户进入某个区域时发布通知。但是,由于相同的两个 CLLocationManagerDelegate 方法,我很困惑。我应该如何正确使用这两种方法?

有人说,如果应用程序在区域中启动,则需要“didDetermineState”方法来启动区域观察。

谢谢,

- (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 的 documentation for CLLocationManager状态:

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.

所以 didDetermineState 应该在 didEnterRegion/didExitRegion 执行时被调用。此外,如果您通过 requestStateForRegion 明确请求状态,它将被调用。

还有一种其他行为会触发此方法:如果您正在监视已启用 notifyEntryStateOnDisplay 属性的区域,则只要用户手动唤醒他们的设备,就会调用该方法,并且他们在您正在监视的区域内。来自 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.

关于ios - iBeacon : What is the difference between didEnterRegion and didDetermineState(CLRegionStateInside),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21214412/

相关文章:

ios - 如何转换到我的 UIViewController

ios - 如何 didAcceptConnectionWithInputStream :outputStream: get called?

ios - iBeacons 发送和接收 UUID

ios - 应用程序在后台运行时如何获取室内位置X和Y位置?

ios - 检测具有不同主要值和次要值的 iBeacon

ios - 如何在 iOS 7 应用程序上启用后台更新

iphone - 如何在 iOS 中更改键盘背景颜色?

ios - UILabel 中看似不受支持的 unicode 字符

充当信标的 Android 设备

ios - 使用 iOS 获取蓝牙 LE 扫描响应数据