问题描述
在使用信标(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. Has anyone experienced anything like this.
推荐答案
检查你的方法是否以下列方式实现。
在 viewDidLoad
中,最后开始监控
Check if your methods are implemented in the following way.In viewDidLoad
, start moniotoring at the end
self.beaconRegion.notifyOnEntry=YES;
self.beaconRegion.notifyOnExit=YES;
self.beaconRegion.notifyEntryStateOnDisplay=YES;
[self.locationManager startMonitoringForRegion:self.beaconRegion];
您所定义区域的请求状态
after monitoring start, request state for your defined region
- (void) locationManager:(CLLocationManager *)manager didStartMonitoringForRegion:(CLRegion *)region
{
[self.locationManager requestStateForRegion:self.beaconRegion];
}
确定状态后,开始测距信标
after state is determined, start ranging beacons
-(void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region
{
if (state == CLRegionStateInside)
{
//Start Ranging
[manager startRangingBeaconsInRegion:self.beaconRegion];
}
else
{
//Stop Ranging here
}
}
并根据您的需要实施以下方法......
and implement the following methods according to your needs...
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region
{
self.statusLbl.text=@"Entered region";
}
-(void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region
{
self.statusLbl.text=@"Exited region";
}
-(void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region
{
if(beacons.count>0)
{}
}
希望这会解决你的问题问题。
Hope this will solve your problem.
这篇关于locationManager:在检测到信标时未调用didEnterRegion的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!