【发布时间】:2012-12-31 10:37:22
【问题描述】:
我目前正在开发其他开发人员启动的 iOS 应用程序。该应用程序需要监控位置变化,因为它需要以低精度(百米)了解用户位置。之前的位置实现是使用NSTimer 和startUpdatingLocation 完成的。执行是这样的:
// Fire each 10 seconds start updating location
self.timerPosition = [NSTimer scheduledTimerWithTimeInterval:ti
target:self
selector:@selector(location)
userInfo:nil
repeats:YES];
[self.timerPosition fire];
位置选择器会这样做
// Configure & check location services enabled
...
self.locman.delegate = self;
self.locman.desiredAccuracy = kCLLocationAccuracyHundredMeters;
[self.locman startUpdatingLocation];
然后在位置管理器委托中
[manager stopUpdatingLocation];
但在 Apple 文档中阅读有关获取用户位置的信息,似乎以低功耗获取位置的正确方法是使用 startMonitoringSignificantLocationChanges。
我的问题是,将定位计时器与startMonitoringSignificantLocationChanges 结合使用而不是startUpdatingLocation 是一个好的决定,还是一种无意义的方法?
当应用处于后台时我不需要获取位置,但我想知道当应用处于活动状态时用户何时更改了位置。
【问题讨论】:
-
这是一种无稽之谈。您应该使用显着的LocationChanges 或RegionMonitoring 服务。如果不需要后台支持,那么我想显着的LocationChanges 可能是更好的方法
标签: ios optimization nstimer cllocationmanager