如何使用 nstimer 为位置管理器设置后台?
我的 ios sdk 有问题。 我需要设置一个计时器,每隔 xx 分钟在后台更新一次手机的位置。 当位置精度达到10米时,应该用我准备好的方法将其保存到本地数据库。 我该怎么办?如何保存电池?有人有一些示例代码来执行此操作吗?
可以使用视图中的按钮启动和停止计时器。
感谢大家
I have a problem with ios sdk.
I need to set a timer that I update the phone's location every xx minutes in the background.
When the position has an accuracy of 10 meters should be saved to a local db with a method that I have ready.
How can I do? How can I preserve the battery? Does anyone have some sample code to do this?
The timer can be started and stopped with a button in a view.
Thanks to all
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不幸的是,当您的应用程序处于后台状态时,NSTimer 会暂停。您需要使用 startMonitoringSignificantLocationChanges 或 startUpdatingLocation 来获取后台状态下的用户位置。
Unfortunately, NSTimer is paused when your app is in background state. You need to use startMonitoringSignificantLocationChanges or startUpdatingLocation to get user's location in background state.