简体   繁体   English

应用终止时更新位置

[英]Update Location when app is terminated

i am working on an app that uses location of the user to send him matched users even if the app is terminated or swiped out from the running apps in iOS. 我正在开发一个使用用户位置向其发送匹配用户的应用程序,即使该应用程序已终止或从iOS中正在运行的应用程序中刷除。 Is there any way that i can call an api to upload the current location of the user if he moves 50 Feet away from his current location or not? 如果用户从当前位置移开50英尺,我有什么方法可以调用api上传用户的当前位置? I have read that apple does not allow code to be executed if the app is in background or terminated. 我已经读到,如果应用程序在后台或终止,Apple不允许执行代码。 So please suggest me what should i do and how should i do it stepwise so that i can accomplish this task and this may help me in many of my apps surely. 因此,请向我建议我应该怎么做以及应该如何逐步执行它,以便我可以完成此任务,并且这肯定会对我的许多应用程序有所帮​​助。

In a word, no. 一言以蔽之。 You could subscribe to significant location change notifications. 您可以订阅重要的位置更改通知。 Then when the system detects that the user has moved by "a significant distance" (defined by the system.) I'm not sure what the system calls a significant location change, but it's going to be a lot more than 50 feet. 然后,当系统检测到用户已经移动了“相当大的距离”(由系统定义)时,我不确定系统将其称为重大的位置变化,但是它将超过50英尺。

Another alternative would be to create a geofence around the user's current location and listen for location updates using the Core Location startMonitoring(for:) function. 另一种选择是在用户的当前位置周围创建地理围栏,并使用“核心位置” startMonitoring(for:)函数侦听位置更新。

Both of those techniques will relaunch your app if they detect a relevant event and your app isn't running. 如果这两种技术都检测到相关事件并且您的应用未运行,则它们将重新启动您的应用。

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

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