在测试使用信标(iOS设备)时,我发现监听信标出现了一些意外的行为。即使信标进入区域,locationManager:didEnterRegion 方法也没有被调用。但是 locationManager:didRangeBeacons:inRegion: 被正确地调用,并且检测到的信标在那里显示。有人经历过类似的情况吗?
在测试使用信标(iOS设备)时,我发现监听信标出现了一些意外的行为。即使信标进入区域,locationManager:didEnterRegion 方法也没有被调用。但是 locationManager:didRangeBeacons:inRegion: 被正确地调用,并且检测到的信标在那里显示。有人经历过类似的情况吗?
请检查您的方法是否按照以下方式实现。
在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)
{}
}
希望这能解决你的问题。
didEnterRegion:
方法中,我们不应该再次分配 CLLocationManager 吗?因为调用可能来自后台。 - Pedro Góesbefore starting coding in project , you must follow given setup guidlines -->
1. in project info or info.plist -->
Custom IOS Target Properties -->
. add "Required background modes"
. in this add two items -->
."App shares data using CoreBluetooth"
."App registers for location updates"
2. in project Capability -->
There is Background Modes
. check "Loaction update"
. check "Acts as a Bluetooth LE accessory"
. check "uses bluetooth LE accessories"
请遵循Davidgyoung先生的指示。相信我,它一定会起作用。
proximityUUID
的信标,并且你的区域定义为仅包含proximityUUID
(没有major和minor值),那么只有以下两种情况会通知你:didEnterRegion:
)。
2. 一个或多个区域内的信标在范围内,然后全部不再可见约30秒(didExitRegion:
)。