停止核心位置更新,然后使用计时器重新启动它们
我想知道是否有人可以向我指出(或粘贴)一些代码来处理关闭核心位置更新以节省电量。
据我了解,一旦获得所需的精度读数,您就应该停止核心位置更新。如果您在一定时间后没有获得良好的准确度读数,您还应该停止更新(大概使用计时器)。每次停止更新时,您应该触发一个计时器(大约 60 秒)来重新启动 Core Location 并获取新的读数。
苹果有没有代码可以完成这一切? LocateMe、TaggedLocations 和 Locations 示例代码似乎没有做到这一点。
I was wondering if anyone could point me to (or paste in) some code to deal with turning off Core Location updates to save power.
As far as I understand it, you should stop Core Location updates as soon as you get a reading of desired accuracy. If you don't get a good accuracy reading after a certain time, you should also stop updates (presumably using a timer). Every time you stop updates, you should fire a timer (around 60 seconds) to restart Core Location and get a new reading.
Is there Apple code which does all this? The LocateMe, TaggedLocations and Locations sample code don't seem to do it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
LocateMe 示例包含您需要的代码。您只需要创建第二个选择器即可触发。
LocateMe 在其设置方法中调用以下内容...
它表示在一定时间 (kSetupInfoKeyTimeout) 后,请调用
stopUpdatingLocation
方法,参数为 NSString = "Timed Out"。在
stopUpdatingLocation
方法内,调用[locationManager stopUpdatingLocation]
来告诉 CoreLocation 停止。因此,您需要做的就是
在
stopUpdatingLocation
方法中添加另一个像这样的选择器...,该方法将在 60 秒后调用timeToRestartCoreLocation
方法。然后在timeToRestartCoreLocation
方法中,调用[locationManager startUpdatingLocation]
再次启动 CoreLocation。The LocateMe example has the code you need. You just need to create a second Selector to Fire.
LocateMe calls the following in it's setup method...
It says that after a certain amount of time (kSetupInfoKeyTimeout), please call the
stopUpdatingLocation
method the the argument of NSString = "Timed Out".Inside the
stopUpdatingLocation
method, the[locationManager stopUpdatingLocation]
is called to tell CoreLocation to stop.So, all you need to do is add another Selector like this...
inside the
stopUpdatingLocation
method, which will call thetimeToRestartCoreLocation
method after 60 seconds. Then inside yourtimeToRestartCoreLocation
method, call[locationManager startUpdatingLocation]
to kick off CoreLocation again.