locationManager:didEnterRegion和didExitRegion永远不会被调用:iBeacon [英] locationManager:didEnterRegion and didExitRegion are never getting called :iBeacon

查看:66
本文介绍了locationManager:didEnterRegion和didExitRegion永远不会被调用:iBeacon的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用信标(iOS设备)进行测试时,我发现侦听器信标给出了一些意外行为。即使信标进入区域,也不会调用locationManager:didEnterRegion方法。但是locationManager:didRangeBeacons:inRegion:被正确调用,并且在那里显示了检测到的信标。

While testing with beacons (ios devices) i found the listener beacon giving some unexpected behavior. locationManager:didEnterRegion method is not getting called even if a beacon enters a region. But the locationManager:didRangeBeacons:inRegion: is getting called correctly, and detected beacons are shown there.

- (void)startListening{

self.locationManager = [[CLLocationManager alloc] init];
[self.locationManager setDelegate:self];
NSUUID *myProximityUUID = [[NSUUID alloc]
                           initWithUUIDString:IDENTIFIER];
_beaconRegion = [[CLBeaconRegion alloc]
                 initWithProximityUUID:myProximityUUID
                 identifier:kPFTransmitterIdentifier];
_beaconRegion.notifyEntryStateOnDisplay = YES;
_beaconRegion.notifyOnEntry  =YES;
[self.locationManager startMonitoringForRegion:self.beaconRegion];

[self.locationManager requestStateForRegion:self.beaconRegion];
//[self.locationManager startRangingBeaconsInRegion:self.beaconRegion];

}

这是代码i

我需要在侦听器应用程序进入特定区域时创建本地通知,即使该应用程序未运行。

i need to create a local notification when the listener app enters a particular region even if the app isn't running.

推荐答案

您的代码可能没有问题。我注意到,如果在检测器已经位于信标区域内(旁边)时打开测试信标,您将不会收到任何有关进入信标区域的通知。这很可能是因为iOS未检测到边界。 iOS似乎在检测到您跨越超出区域和内部区域(沿任一方向)之间的边界时发出通知,然后才调用适当的委托方法。
要进行测试,只需打开信标,但将检测器保持关闭即可。然后,如上面的davidgyoung所示,从信标走200英尺。然后打开检测器并向信标走去。输入区域时,您应该收到 didEnterBeaconRegion通知。
您可以尝试做的另一件事是实现 locationManagerDidDetermineStateForRegion委托方法,只要定义的受监视区域的状态发生变化(无论何时打开检测器),都将调用该方法。如果这样做,即使启动时检测器已位于信标区域内,也应获得回调。但是请注意,这不会在后台发生,因此您仍然还需要其他回调。

It's possible nothing is wrong with your code. I've noticed that if you turn your test beacon on when the detector is already inside the beacon region (next to it), you will NOT get any notification that you entered the beacon region. That's most likely because iOS did not detect a boundary crossing. iOS seems to notify when it detects that you have crossed the boundary between "out of region" and "inside region" (in either direction) and only then calls the appropriate delegate methods. To test this, simply turn on your beacon but leave your detector OFF. Then, as indicated by davidgyoung above, walk 200 feet away from your beacon. THEN turn the detector ON and walk toward the beacon. You should get a "didEnterBeaconRegion" notification when you enter the region. Another thing you can try is to implement the "locationManagerDidDetermineStateForRegion" delegate method, which is called whenever the state of a defined monitored region changes, which happens whenever you turn on your detector. If you do that, you should get a callback even if your detector is already inside the beacon region when initiated. But note this does not happen in the background so you still need the other callbacks as well.

这篇关于locationManager:didEnterRegion和didExitRegion永远不会被调用:iBeacon的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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