使用标准位置服务跟踪前台/后台应用程序中的行驶距离 [英] Use of Standard location service for tracking traveled distance in a foreground/background app

查看:133
本文介绍了使用标准位置服务跟踪前台/后台应用程序中的行驶距离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须开发一种GPS导航应用程序,需要不断跟踪正在驾车的用户的位置。
在具体情况下,我不必在地图上显示当前位置,只需以尽可能准确的方式记录其位置,以便计算行驶的总行程。

当然,如果用户切换到另一个应用程序,打电话或者类似的东西,应用程序需要在后台继续工作......



从我所做的测试以及从这些有用的帖子(以及 documentation ),在我看来,在这种情况下最好的选择是标准位置服务,配置了应用程序<斯特龙g> UIBackgroundModes =位置在.plist文件中。
通过这种方式,即使在后台,它也将继续接收位置更新,并且永远不会被操作系统暂停(只有在调用了[locationManager startUpdatingLocation]的情况下,这实际上才是真正的)。这也通过这家伙
我亲自验证过,只需运行带有Instruments和Memory monitor模块的应用程序即可,您可以在其中查看有关应用程序状态的各种标志,首先将应用程序置于后台,将UIBackgroundModes设置为位置,并启动startUpdatingLocation,并在没有它之后。


  • 1)我现在想知道当应用程序正在跟踪位置即可。我不想丢失任何位置更新,所以只要有新的更新可用,我就需要重新唤醒它。
    文档说:



重要提示:applicationWillTerminate:方法在您的$

但是因为在我的情况下,它永远不会被暂停(它会保持在后台但不会暂停),我的逻辑结论是,applicationWillTerminate将始终被调用,因此我可以在此方法内部注册一个重要的位置更新或区域监视,以便唤醒并重新启动标准位置服务。
是applicationWillTerminate放置此代码的正确位置吗?

$ b


  • 2)应用程序在后台工作但未挂起可能会被操作系统终止,除了非常低的内存条件之外没有其他原因,或者我的应用没有正确响应内存警告? (用户也可以手动关闭它)。我担心applicationWillTerminate是否会以某种方式被调用。

  • 3)Apple可能不批准在后台不断使用标准位置服务的应用程序,因为它的快速电池消耗?
    您是否曾经对类似的应用程序有过批准?

    >因为你问了很多问题,你不应该在这里做,我只能给你一部分aswrs。



    如果应用程序终止,那么你不能重新启动它了。
    这通常是用户终止应用程序时的情况。

    不要担心Apple(ios)不会终止您的应用程序。你的应用程序不会占用太多内存,具有巨大位图图形的游戏更有可能成为终端。

    $ b


    1. evry gps应用程序将消耗蝙蝠。这不是不赞成的原因。

    2. 挂起意味着应用程序不处于后台模式,它正在休眠。你将不会收到Gps,所以没有必要打电话给你终止。您必须先保存数据,然后查看关于后台模式和应用生命周期的Apple文档。

    3. I have to develop a kind of GPS navigation application that needs to constantly keep track of the position of the user, which is moving by car. In the specific, I don't have to display the current location on a map but just to record its position with the best possible precision in order to calculate the total distance traveled.

      Of course the application needs to continue its work in background if the user switch to another app, a phone call come in or something like that…

      From the tests I have made and from what I have learned from this useful post (and from the documentation), it seems to me that the best choice in this case is the Standard location service, with the application configured with the UIBackgroundModes = location in the .plist file. In this way it will continue to receive the location updates even if in background and it will never be suspended by the OS (this is actually true only if [locationManager startUpdatingLocation] has been called). This is also confirmed by this guys. I have personally verified that is true simply by running the app with Instruments and the Memory monitor module where you can see the various flags about the app states, putting the app in background first with UIBackgroundModes set to location and startUpdatingLocation active, and after without it.

      • 1) I'm now wondering what to do when the app is terminated when it is tracking the position. I don't want to loose any location updates so I need to wake up it again whenever a new update is available. The documentation say:

      Important: The applicationWillTerminate: method is not called if your app is currently suspended.

      But because in my case it will be never suspended (it will stay in background but not suspended), my logical conclusion is that applicationWillTerminate will be always called and so I could register for a Significant location update or Region monitoring inside of this method in order to be waked up and then restart the Standard location service. Is applicationWillTerminate the right place to put this code?

      • 2) An application working in background but not suspended could be terminated by the OS for no other reasons than a very low memory condition or for my app don't properly respond to a memory warning? (the user could also manually close it). I was concerned if applicationWillTerminate wouldn't be called in some way.

      • 3) Could Apple not approve an app which constantly use the standard location services in background because of its quick battery drain? Have you ever had approve problems for similar apps?

      解决方案

      since you are asking many questions which you shoukd not do here, i cam give you only aswrs to a part of it.

      if the app is terminated, then you cannot restart it anymore. This is usually the case when the user terminates the app.
      Dont worry Apple ( ios) will not terminate your app. your app will not use much memory, games with huge bitmap graphics are more likely to be termin.

      1. evry gps app will drain the bat. that is not a reason for not aproving.

      2. suspended means that app is not in background mode, it is sleeping. you will not receive Gps, so there is no need to call you on terminate. you have to save data before, see the apple docu on background modes and app life cycle.

      这篇关于使用标准位置服务跟踪前台/后台应用程序中的行驶距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆