[英]How to get background updates for iBeacons without using locationManager didEnterRegion
[英]locationManager: didEnterRegion: triggered without location change
我有一个应用程序,它监视每个区域代表商店的某些区域(地理围栏),该应用程序会在用户接近商店时通知用户。
由于某种原因,当用户已经在区域圈子中时,该应用程序每20分钟发送一次通知。
一切正常,但是当用户长时间处于某个区域内时,应用程序会一直通知他,直到他退出该区域为止。
知道为什么会这样吗? 谢谢!
当您创建一个locationManager并调用startUpdatingLocation时,它将开始连续为您提供模拟器或设备的坐标,但坐标值存在很小的差异。 您需要调用stopUpdatingLocation。
For your case you need to stopUpdatingLocation when user exist the region or you can record the last location like this:
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
CLLocation *newLocation = [locations lastObject];
[locationManager stopUpdatingLocation];
}
我们正在发生同样的事情。 我们只是跟踪区域坐标,当新坐标出现时,我们就有一种方法来确定新坐标是否与我们所在的区域“显着不同”。如果不是,则忽略它。 如果是这样,那么我们将采取下一个适当的措施。 希望对您有所帮助!
*更新*
这是我们确定有足够的更改采取行动的方式:
- (BOOL) radiiAreSignificantlyDifferent:(CLLocationDistance) newRadius oldRadius:(CLLocationDistance)oldRadius
{
// radii are in kilometers
return (newRadius > oldRadius + 1.5 || newRadius < oldRadius - 1.5) ? YES : NO;
}
- (BOOL) locationsAreSignificantlyDifferent:(CLLocation*) newLocation oldLocation:(CLLocation*)oldLocation
{
BOOL different = NO;
if (oldLocation == nil) {
different = YES;
}else{
// have we moved at least a quarter mile?
different = ([newLocation distanceFromLocation:oldLocation] > 400.0)? YES : NO;
}
return different;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.