问题描述
我想在用户进入某个地区时发布通知。但是,由于同样的两个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的指出:
每当 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
这篇关于iBeacon:didEnterRegion和didDetermineState(CLRegionStateInside)之间有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!