简体   繁体   English

2分钟后如何停止定位服务而没有任何重大动作?

[英]How to stop the location services after 2 min without any significant move?

My app is in the background . 我的应用程序在后台 I would like to stop (or pause) the locationupdate after 2.5 min detecting that the user didn't move significantly and start to listen instead startMonitoringSignificantLocationChanges . 我想检测到用户没有明显移动2.5分钟后 停止 (或暂停) locationupdate,然后开始监听,而不是startMonitoringSignificantLocationChanges Their is an option: PausesLocationUpdatesAutomatically but the problem is that this option is a little obscure. 它们是一个选项:自动PausesLocationUpdatesAutomatically但问题是此选项有点晦涩。 We don't really know when the system will pause the GPS (seam only after 20 min) and strangely, at the opposite what the doc say, the system will resume himself the locationUpdate (at least when you will put the app in foreground). 我们真的不知道什么时候系统会暂停GPS(仅在20分钟后才关闭),而奇怪的是,与文档所说的相反,系统将自行恢复locationUpdate(至少当您将应用程序置于前台时) 。

So i have another option: DistanceFilter . 所以我有另一个选择: DistanceFilter I can set it to none and the system will wake up my app every 5 seconds with new location (same as before if user didn't move). 我可以将其设置为none,系统将每5秒钟用新位置唤醒我的应用(如果用户没有移动,则与以前相同)。 The problem wake up the app every 5 second seam a little aggressive for the battery (my app will be wake up more than 30 times before i reach the 2.5 min to stop the location services). 该问题每隔5秒就唤醒应用程序一次,从而对电池产生一些攻击性(我的应用程序将唤醒30次以上,直到我到达2.5分钟以停止定位服务为止)。 also it's a disaster when user move not very fast, my app will be constantly wake up every 5 second, and i need only an accuracy of 100 meters :( 当用户移动不快时,这也是一个灾难,我的应用程序将每隔5秒不断唤醒,而我只需要100米的精度即可:(

So this is my problem, how to stop the locationservices after 2.5 min when their is no significant move ? 所以这是我的问题,如何在2.5分钟内无明显变化的情况下停止定位服务?

so from Apple documentation you got in AppDelegate this method 因此从Apple文档中您可以在AppDelegate中获得此方法

func applicationDidEnterBackground(_ application: UIApplication)

I will call this PausesLocationUpdatesAutomatically and set a timer after 2min to turn it off. 我将自动调用此PausesLocationUpdatesAutomatically并在2 PausesLocationUpdatesAutomatically后设置一个计时器将其关闭。

anyhow also another solution would be to get the current location and set a timer to stop locating after 2min in meantime i will still receive location and check is it more 100m and if it was more i will reset the timer and continue 无论如何,另一个解决方案是获取当前位置并设置计时器,使其在2分钟后停止定位,同时我仍然会收到位置并检查是否超过100m,如果更多则我将重置计时器并继续

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM