iBeacon每1分钟不断进出区域

Thu*_*Ngo 3 objective-c cllocationmanager ios7 ibeacon

当iBeacon(使用Kontakt Beacon)在后台模式下进入区域时,我设法获得本地通知.同时我监控3个具有特定和唯一标识符的信标区域(每个标识符具有相同的UUID,但具有唯一的主要和次要组合).在锁定屏幕模式下,我的应用程序可以通知这些信标何时出现,但我不知道为什么即使信标和我的应用程序仍然几乎彼此相邻,代理人DidExitRegion仍然被调用,请查看我的日志.

2014-01-18 11:56:49.828 sunlandbeacon [1385:60b]进入非活动模式

2014-01-18 11:56:49.848 sunlandbeacon [1385:60b]带徽章的EnterBackgroundMode 0

2014-01-18 11:57:28.629 sunlandbeacon [1385:60b]退出灯塔范围

2014-01-18 11:57:29.305 sunlandbeacon [1385:60b]本地通知发生在徽章1

2014-01-18 11:57:29.307 sunlandbeacon [1385:60b]输入带有flagvalue 1的区域1

2014-01-18 11:58:15.173 sunlandbeacon [1385:60b]退出灯塔范围

2014-01-18 11:58:15.176 sunlandbeacon [1385:60b]退出灯塔范围

2014-01-18 11:58:15.178 sunlandbeacon [1385:60b]退出灯塔范围

2014-01-18 11:58:15.880 sunlandbeacon [1385:60b]本地通知发生在徽章2

2014-01-18 11:58:15.886 sunlandbeacon [1385:60b]输入带有flagvalue 1的区域1

2014-01-18 11:58:16.175 sunlandbeacon [1385:60b]本地通知发生在徽章3

2014-01-18 11:58:16.184 sunlandbeacon [1385:60b]输入带有flagvalue 2的区域2

2014-01-18 11:59:02.784 sunlandbeacon [1385:60b]退出灯塔范围

2014-01-18 11:59:02.787 sunlandbeacon [1385:60b]退出灯塔范围

2014-01-18 11:59:02.790 sunlandbeacon [1385:60b]退出灯塔范围

2014-01-18 11:59:03.491 sunlandbeacon [1385:60b]本地通知发生在徽章4

2014-01-18 11:59:03.493 sunlandbeacon [1385:60b]输入带有flagvalue 1的区域1

2014-01-18 11:59:03.792 sunlandbeacon [1385:60b]本地通知发生在徽章5

2014-01-18 11:59:03.796 sunlandbeacon [1385:60b]输入带有flagvalue 2的区域2

dav*_*ung 10

CoreLocation定期出现"故障"并向您发送通知说您退出该区域并且稍后再说您进入同一区域的情况并不少见.

在没有看到您的代码的情况下,很难确定这是发生了什么,但如果是,您可以通过在退出时添加软件过滤器并输入事件来轻松解决这个问题.如果在前几秒内发生同一区域的条目事件,则基本上忽略退出事件.同样,如果同一区域的退出事件在前几秒内发生,则忽略条目事件.

为此,您需要保留两个表,一个包含按区域键入的最新条目事件,其中包含按区域键入的最新退出事件.

下面是一个放在didEnterRegion回调方法顶部的代码示例,该方法使用名为_enteredTimes的类级NSMutableDictionary作为查找表来完成此任务:

NSDate *now = [[NSDate alloc] init];
CLBeaconRegion *beaconRegion = (CLBeaconRegion *) region;
NSString *regionKey = [NSString stringWithFormat: @"%@_%@_%@", beaconRegion.proximityUUID, beaconRegion.major, beaconRegion.minor];
NSDate *lastEntered = [_enteredTimes valueForKey:regionKey];
[_enteredTimes setValue: now forKey: regionKey]; 
if (lastEntered != Nil && [now timeIntervalSinceDate:lastEntered] < 10) { // last 10 secs
    // ignore this event
    return;
}
Run Code Online (Sandbox Code Playgroud)

您必须在didExitRegion回调中输入等效代码.