简体   繁体   English

应用程序终止时使用位置更新

[英]Working with location updates when app is terminated

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. 我已经使用了所有可能的解决方案,但它仍然无法终止。现在我想澄清一个疑问 - 我正在使用startUpdatingLocation()作为前景和背景。 As we know that startMonitoringSignificantLocationChanges() is the only method that relaunch app in case of any location update. 我们知道startMonitoringSignificantLocationChanges()是在任何位置更新的情况下重新启动应用程序的唯一方法。 Can we call "startMonitoringSignificantLocationChanges()" in applicationWillTerminate() method? 我们可以在applicationWillTerminate()方法中调用“startMonitoringSignificantLocationChanges()”吗? and Will that work and relaunch app when there is any significant location update? 当有任何重要的位置更新时,它会工作并重新启动应用程序吗? Please tell me. 请告诉我。

Thank!! 谢谢!!

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. 您不能在applicationWillTerminate() ,因为closure现在不会返回值。如果您想要始终获取用户位置,请尝试后台模式。

This is the description in Apple Document: 这是Apple文档中的描述:

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. 在这种情况下,传递给application:willFinishLaunchingWithOptions:的选项字典application:willFinishLaunchingWithOptions:application:didFinishLaunchingWithOptions:应用程序委托的方法包含密钥UIApplicationLaunchOptionsLocationKey以指示您的应用程序是由于位置事件而启动的。 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. 它清楚地告诉你如何获得位置。

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

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