【发布时间】:2017-12-25 22:08:39
【问题描述】:
我想每 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
}
【问题讨论】:
-
您将无法做到这一点。您不能只跟踪人们的位置。
-
是否有任何选项可以使应用程序始终在后台运行。不允许用户关闭应用程序,或者如果他们关闭,则使应用程序在后台运行。