应用终止时处理位置更新 [英] Working with location updates when app is terminated

查看:58
本文介绍了应用终止时处理位置更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个项目中,即使应用程序终止,我也试图在所有状态下获取位置更新.我已经使用了所有可能的解决方案,但在终止的情况下仍然无法使用.现在我想清除一个疑问-我将startUpdatingLocation()用于前景和背景.我们知道,在任何位置更新的情况下,startMonitoringSignificantLocationChanges()是重新启动应用程序的唯一方法.我们可以在applicationWillTerminate()方法中调用"startMonitoringSignificantLocationChanges()"吗?并且在进行重大位置更新时,该功能可以正常工作并重新启动应用程序吗?请告诉我.

I am working on a project in which i am trying to get location updates in all states, even when app is terminated. I have used all possible solutions but still it's not working in case of termination.For now I want to clear a doubt - I am using startUpdatingLocation() for foreground and background. As we know that startMonitoringSignificantLocationChanges() is the only method that relaunch app in case of any location update. Can we call "startMonitoringSignificantLocationChanges()" in applicationWillTerminate() method? and Will that work and relaunch app when there is any significant location update? Please tell me.

谢谢!

推荐答案

您不能在applicationWillTerminate()中执行此操作,因为闭包现在不会返回任何值.如果要一直获取用户位置,请尝试使用Background模式.

You cannot do that in applicationWillTerminate(),because closure won't return a value right now.If you want to get user location all the time,try Background Mode.

这是Apple文档中的描述:

This is the description in Apple Document:

在这种情况下,传递给应用程序委托的application:willFinishLaunchingWithOptions:application:didFinishLaunchingWithOptions:方法的选项字典包含键UIApplicationLaunchOptionsLocationKey,以指示由于位置事件而启动了您的应用程序.重新启动后,您仍必须配置位置管理器对象并调用此方法以继续接收位置事件.当您重新启动位置服务时,当前事件将立即传递给您的委托.此外,即使在您启动位置服务之前,位置管理器对象的location属性也会填充有最新的位置对象.

In such a case, the options dictionary passed to the application:willFinishLaunchingWithOptions: and application:didFinishLaunchingWithOptions: methods of your app delegate contains the key UIApplicationLaunchOptionsLocationKey to indicate that your app was launched because of a location event. Upon relaunch, you must still configure a location manager object and call this method to continue receiving location events. When you restart location services, the current event is delivered to your delegate immediately. In addition, the location property of your location manager object is populated with the most recent location object even before you start location services.

它清楚地告诉您如何获取位置.

It clearly tells you how to get the location.

这篇关于应用终止时处理位置更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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