iBeacon:didEnterRegion和didDetermineState(CLRegionStateInside)之间有什么区别 [英] iBeacon : What is the difference between didEnterRegion and didDetermineState(CLRegionStateInside)

查看:659
本文介绍了iBeacon:didEnterRegion和didDetermineState(CLRegionStateInside)之间有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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?

有些人说如果应用程序在该地区开始,则需要didDetermineState方法来启动区域观察。

Some people say "didDetermineState" method is needed to start region observation if the app start in the region.

谢谢,

- (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的 CLLocationManager的文档指出:


只要区域有边界转换,位置管理器就会调用此方法。除了调用 locationManager:didEnterRegion: locationManager:didExitRegion:方法之外,它还调用此方法。位置管理器还调用此方法以响应对其 requestStateForRegion:方法的调用,该方法异步运行。

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.

每当 didEnterRegion / didExitRegion <时,应该调用 didDetermineState / code>做。此外,如果您通过 requestStateForRegion 显式请求状态,则会调用它。

So didDetermineState should get called whenever didEnterRegion/didExitRegion do. In addition, if you explicitly request the state via requestStateForRegion it will be called.

还有一个其他行为会触发此方法:如果您正在监视已启用 notifyEntryStateOnDisplay 属性的区域,则只要用户手动唤醒其设备,就会调用该方法,并且它们位于您正在监控的地区。来自文档

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


当设置为YES时,位置管理器会在用户打开显示器并且设备已在设备内时发送信标通知地区。即使您的应用未运行,也会发送这些通知。在这种情况下,系统会将您的应用程序启动到后台,以便它可以处理通知。在这两种情况下,位置管理器都会调用 locationManager:didDetermineState:forRegion:其委托对象的方法。

这篇关于iBeacon:didEnterRegion和didDetermineState(CLRegionStateInside)之间有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆