iBeacon每1分钟不断进出区域 [英] iBeacon enter and exit region constantly every 1 minute

查看:108
本文介绍了iBeacon每1分钟不断进出区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I managed to get local notification when iBeacon (using Kontakt Beacon) enter a region in Background mode . at the same time I monitor 3 beacon regions with specific & unique Identifier (each has same UUID but unique Major and Minor combination). In Lock Screen Mode, my app can notify when these beacons present, but I don't know why even the beacons and my app all stay still almost next to each other, the delegate DidExitRegion is still called, please look at my Log.


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

2014-01-18 11:56:49.828 sunlandbeacon[1385:60b] Enter Inactive mode

2014-01-18 11:56:49.848 sunlandbeacon [1385:60b] EnterBackgroundMode
with badge 0

2014-01-18 11:56:49.848 sunlandbeacon[1385:60b] EnterBackgroundMode with Badge 0

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

2014-01-18 11:57:28.629 sunlandbeacon[1385:60b] Exit a beacon range

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

2014-01-18 11:57:29.305 sunlandbeacon[1385:60b] Local Notification Happens with Badge 1

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

2014-01-18 11:57:29.307 sunlandbeacon[1385:60b] Enter Region 1 with flagvalue 1

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

2014-01-18 11:58:15.173 sunlandbeacon[1385:60b] Exit a beacon range

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

2014-01-18 11:58:15.176 sunlandbeacon[1385:60b] Exit a beacon range

2014-01-18 11:58:15.178 sunlandbeacon [1385:60b]退出a信标范围

2014-01-18 11:58:15.178 sunlandbeacon[1385:60b] Exit a beacon range

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

2014-01-18 11:58:15.880 sunlandbeacon[1385:60b] Local Notification Happens with Badge 2

2014-01-18 11:58:15.886 sunlandbeacon [1385:60b]进入Regi 1美元兑换
flagvalue 1

2014-01-18 11:58:15.886 sunlandbeacon[1385:60b] Enter Region 1 with flagvalue 1

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

2014-01-18 11:58:16.175 sunlandbeacon[1385:60b] Local Notification Happens with Badge 3

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

2014-01-18 11:58:16.184 sunlandbeacon[1385:60b] Enter Region 2 with flagvalue 2

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

2014-01-18 11:59:02.784 sunlandbeacon[1385:60b] Exit a beacon range

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

2014-01-18 11:59:02.787 sunlandbeacon[1385:60b] Exit a beacon range

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

2014-01-18 11:59:02.790 sunlandbeacon[1385:60b] Exit a beacon range

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

2014-01-18 11:59:03.491 sunlandbeacon[1385:60b] Local Notification Happens with Badge 4

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

2014-01-18 11:59:03.493 sunlandbeacon[1385:60b] Enter Region 1 with flagvalue 1

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

2014-01-18 11:59:03.792 sunlandbeacon[1385:60b] Local Notification Happens with Badge 5

2014-01-18 11:59:03.796 sunlandbeacon [1385:60b]使用
flagvalue 2

2014-01-18 11:59:03.796 sunlandbeacon[1385:60b] Enter Region 2 with flagvalue 2

输入区域2

推荐答案

CoreLocation定期发生故障并向您发送通知说您退出该地区并且后来又说了一秒钟并不少见你进入了同一个区域。

It is not uncommon for CoreLocation to periodically have a "glitch" and send you a notification saying you exited the region and then a second later say you entered that same region.

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

Without seeing your code, it's hard to say for certain that this is what happening, but if it is, you can fix this easily enough by adding a software filter on your exit and enter events. You basically ignore an exit event if an entry event happened for the same region within the previous few seconds. Likewise, you ignore an entry event if an exit event for the same region happened within the previous few seconds.

为了做到这一点,你需要保留两个表,一个包含按区域键入的最新条目事件,其中包含按区域键入的最新退出事件。

In order to do this you need to keep two tables, one that contains the most recent entry events keyed by region, and on that contains the most recent exit events keyed by region.

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

Here's an example of code to put at the top of a didEnterRegion callback method that uses a class-level NSMutableDictionary called _enteredTimes as a lookup table to accomplish this:

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;
}

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

You have to put equivalent code in your didExitRegion callback.

这篇关于iBeacon每1分钟不断进出区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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