我想每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
}
答案 0 :(得分:0)
到目前为止,Apple尚未提供在应用处于非活动状态时跟踪用户位置的工具。因此,当应用处于非活动状态或被终止或终止时,您无法跟踪用户的位置。