在使用信标(iOS设备)测试时,我发现听众信标发出了一些意想不到的行为. locationManager:didEnterRegion方法即使信标进入区域也不会被调用.但是locationManager:didRangeBeacons:inRegion:被正确调用,并且在那里显示检测到的信标.有没有人经历过这样的事情.
解决方法
检查您的方法是否以下列方式实现.
在viewDidLoad中,最后启动单轨
在viewDidLoad中,最后启动单轨
self.beaconRegion.notifyOnEntry=YES; self.beaconRegion.notifyOnExit=YES; self.beaconRegion.notifyEntryStateOnDisplay=YES; [self.locationManager startMonitoringForRegion:self.beaconRegion];
监控开始后,请为您定义的区域请求状态
- (void) locationManager:(CLLocationManager *)manager didStartMonitoringForRegion:(CLRegion *)region { [self.locationManager requestStateForRegion:self.beaconRegion]; }
状态确定后,开始测距信标
-(void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region { if (state == CLRegionStateInside) { //Start Ranging [manager startRangingBeaconsInRegion:self.beaconRegion]; } else { //Stop Ranging here } }
并根据您的需要实施以下方法…
- (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) {} }
希望这将解决你的问题.