将用户位置发送到服务器(Web文件)甚至应用程序已关闭或终止或终止iOS Swift

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了将用户位置发送到服务器(Web文件)甚至应用程序已关闭或终止或终止iOS Swift相关的知识,希望对你有一定的参考价值。

我想每5分钟将用户当前位置发送到服务器文件,后台工作正常

我的问题是如何在applicationWillTerminate中使用甚至应用程序被关闭或杀死

var timer = Timer() 
func applicationDidEnterBackground(_ application: UIApplication) {
    timer.invalidate() // just in case this button is tapped multiple times

     timer = Timer.scheduledTimer(timeInterval: 0.5, target: self, selector: #selector(timerAction), userInfo: nil, repeats: true)

}


func timerAction() {

     //call the location manger to update the location to the server
}

func applicationWillTerminate(_ application: UIApplication) {

//need code to call continuously  even app closed

}
答案

到目前为止,Apple尚未提供在应用程序处于非活动状态时跟踪用户位置的工具。因此,当应用处于非活动状态或被终止或终止时,您无法跟踪用户的位置。

以上是关于将用户位置发送到服务器(Web文件)甚至应用程序已关闭或终止或终止iOS Swift的主要内容,如果未能解决你的问题,请参考以下文章