简体   繁体   English

应用程序终止时iOS 10更新位置

[英]iOS 10 update location when app is terminated

I'm making an app where I am showing the User's distance from other users. 我正在创建一个应用程序,用于显示用户与其他用户的距离。 I'm able to update user locations when app is open and when app is in background HOWEVER I can not figure out how to update the location when app is terminated. 我可以在应用程序打开时和应用程序处于后台时更新用户位置但是我无法弄清楚应用程序终止时如何更新位置。 I have been told that this is not possible but I believe it is possible because Life 360, Facebook, etc update the location in terminated state. 我被告知这是不可能的,但我相信这是可能的,因为Life 360​​,Facebook等更新了终止状态的位置。 Any help on how to achieve this is greatly appreciated! 任何有关如何实现这一目标的帮助非常感谢!

To do this you need to use: 为此,您需要使用:

myLocationManager.startMonitoringSignificantLocationChanges() myLocationManager.startMonitoringSignificantLocationChanges()

From the docs: 来自文档:

" If you start this service and your app is subsequently terminated, the system automatically relaunches the app into the background if a new event arrives. " 如果您启动此服务并且您的应用程序随后被终止,则系统会在新事件到来时自动将应用程序重新启动到后台。

Unfortunately from extensive testing the significant changes when they start to come through are very inaccurate so you may wish to switch on normal location updates at the point you receive a significant location change in the background. 不幸的是,通过大量测试,当它们开始出现时的重大变化是非常不准确的,因此您可能希望在后台收到重大位置更改时打开正常位置更新。

myLocationManager.startUpdatingLocation() myLocationManager.startUpdatingLocation()

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

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